views:

69

answers:

1

I'm using Hunchentoot and would like to change the name of the session cookie. This is implemented with a generic function and the docs say to change the name you can "specialize the function".

I'm not really sure what this means here. I was under the impression that specializing a function is to dispatch a method on certain argument types. In this particular case, the function takes the server acceptor and I don't want to change that. Can someone illuminate me on this?

The API: http://weitz.de/hunchentoot/#session-cookie-name

Here's the implementation in the source:

 (defgeneric session-cookie-name (acceptor)                                          
    (:documentation "Returns the name \(a string) of the cookie \(or the              
    GET parameter) which is used to store a session on the client side.                 
    The default is to use the string \"hunchentoot-session\", but you can               
    specialize this function if you want another name."))                               

 (defmethod session-cookie-name ((acceptor t))
    "hunchentoot-session")
+2  A: 

Make a subclass and specialize that way:

(defclass my-acceptor (hunchentoot:acceptor) ())

(defmethod session-cookie-name ((acceptor my-acceptor)) 
  "my-session")

The function still takes an acceptor, it's just your kind of acceptor, now.

Xach
Thanks, this works. If anyone is experimenting, make sure you define the method on hunchentoot:session-cookie-name
MarcusBooster