使用 hunchentoot 重定向到 https

ark*_*ark 5 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*)
Run Code Online (Sandbox Code Playgroud)

rsm*_*rsm 4

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

(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
Run Code Online (Sandbox Code Playgroud)

...然后也启动它:

(hunchentoot:start *http-handler*)
Run Code Online (Sandbox Code Playgroud)

此版本仅重定向到索引/