使用hunchentoot

时间:2019-05-02 20:52:27

标签: common-lisp hunchentoot

我已经用ssl设置了hunchentoot服务器。我希望将常规http请求重定向到https。

看来hunchentoot:define-easy-handlerhunchentoot:redirect的某种组合是可行的方法,但我无法弄清楚。

这是我到目前为止所拥有的:

(defvar *https-handler*
  (make-instance 'hunchentoot:easy-ssl-acceptor
                 :name 'ssl
                 :ssl-privatekey-file #P"/path/to/privkey.pem"
                 :ssl-certificate-file #P"/path/to/cert.pem"
                 :port 443))

(hunchentoot:start *https-handler*)

2 个答案:

答案 0 :(得分:2)

是的,您可以添加带有重定向到ssl版本的简单http处理程序:

(defvar *http-handler*
  (make-instance 'hunchentoot:easy-acceptor
                 :name 'http
                 :port 80))

(hunchentoot:define-easy-handler (redir-to-ssl :uri (lambda (uri) t) :acceptor-names '(http)) ()
  (hunchentoot:redirect "/" :protocol :https)) ; where magic happens

...然后再启动它:

(hunchentoot:start *http-handler*)

此版本仅重定向到索引/

答案 1 :(得分:1)

好吧,我直接使用hunchentoot:*dispatch-table*。除非我在处理程序中使用hunchentoot:redirect,否则将其重定向到与我发现的路径无关的方法是使用(hunchentoot:ssl-p)。我的大多数defun处理程序都包装在一个宏中以进行身份​​验证。因此,我只需要修改该宏,然后修改M-x slime-who-macroexpands-> C-c C-k

(unless (hunchentoot:ssl-p)
  (hunchentoot:redirect (hunchentoot:request-uri*)
                       :protocol :https))