如何通过专门化函数来更改 Hunchentoot 会话 cookie 名称?

发布于 2024-08-18 13:50:05 字数 889 浏览 7 评论 0原文

我正在使用 Hunchentoot,并且想更改会话 cookie 的名称。这是用通用函数实现的,文档说要更改名称,您可以“专门化函数”。

我不太确定这在这里意味着什么。我的印象是,专门化一个函数就是在某些参数类型上调度一个方法。在这种特殊情况下,该函数采用服务器接受器,我不想更改它。有人可以帮我解释一下吗?

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

这是源代码中的实现:

 (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")

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")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2024-08-25 13:50:06

创建一个子类并以这种方式专门化:

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

(defmethod session-cookie-name ((acceptor my-acceptor)) 
  "my-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文