[hunchentoot-devel] per server easy-handler-alist

Mac Chan emailmac at gmail.com
Fri May 18 21:56:29 UTC 2007


Since Edit added the ultra-flexible macro define-easy-handler, I have
replaced all my custom dispatch functions with it.

There's a small issue with this macro, since it modifies the global
*easy-handler-alist*.

In production I have two server instances, one http and one https.

I cannot easily say, for example, I want the following apply only to
the https server instance.

(define-easy-handler (home-page :uri "/login") ()
  (with-html ...))

(define-easy-handler (home-page :uri "/my-account") ()
  (with-html ...))


The problem is that start-server happens at run-time but
define-easy-handler happens at load-time, so you cannot associate any
server specific binding in define-easy-handler.

Attached is a patch that introduce a slot :name to the server class
and a global variable *servers* which is an a-list mapping names to
server instances.

With this you can do something like

(define-easy-handler (home-page :uri "/hunchentoot/test/easy-home.html"
                                :server-names '(:http))
    ()
  (with-html (:html (:body "Home page"))))

(define-easy-handler (login-page :uri "/hunchentoot/test/easy-login.html"
                                 :server-names '(:https))
    ()
  (with-html (:html (:body "Secure login"))))

(define-easy-handler (common-page :uri "/hunchentoot/test/easy-common.html"
                                  :server-names '(:https :http))
    ()
  (with-html (:html (:body "Common page"))))

(start-server :name :http :port 8000)
(stop-server :http)

(start-server :name :https :port 4443)
(stop-server :https)

If you are not using multiple servers, this change will be transparent.

I'd appreciate any suggestions.

Regards,
-- Mac



More information about the Tbnl-devel mailing list