Method around
Adding db-path
as a slot in the acceptor may be an appropriate option. However, you can also write an around
method for handle-request
. Assuming *my-acceptor*
globally bound:
(defmethod hunchentoot:handle-request :around ((acceptor (eql *my-acceptor*)) request) (let ((*db-path* "my-db-file")) (call-next-method)))
Of course, you donโt need to specialize in EQL
, instead you can define your own subclass. The advantage of the around method associated with storing the configuration variable in an instance of the class is that you retain the benefits of using special variables, i.e. Bindings are visible throughout the dynamic area. This is what the documentation line visible on Lispdoc says about handle-request
(my highlight):
This function is called after the request has been read and the REQUEST object has been created. His task is to actually cope with the request, i.e. return something to the customer.
Perhaps a good place for methods specifically designed for your ACCEPTOR subclass, which bind or rearrange special variables that your handlers can then access.
I recommend that you read the Hunchentoot documentation .
Special Variables and Streams
The behavior you observe is related to the fact that:
If you create your own threads, you can create a closure that binds the variables as you wish. You can also rely on the portable bordeaux-threads library, which takes a list of bindings to be efficient inside the thread.
source share