开发者

How to change a Hunchentoot session cookie name by specializing a function?

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 \"hunchent开发者_C百科oot-session\", but you can               
    specialize this function if you want another name."))                               

 (defmethod session-cookie-name ((acceptor t))
    "hunchentoot-session")


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜