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

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

On Fri, 18 May 2007 14:56:29 -0700, "Mac Chan" <emailmac@gmail.com> wrote:
Since Edit added the ultra-flexible macro define-easy-handler, I have replaced all my custom dispatch functions with it.
Edit. Hmm... You're not the first one. Maybe I should change my name... :)
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.
I think you forgot the patch.
I'd appreciate any suggestions.
At a first glance, this seems like a useful change to me. I have to think about it a bit more.

On 5/18/07, Edi Weitz <edi@agharta.de> wrote:
Edit. Hmm... You're not the first one. Maybe I should change my name... :)
I have an excuse - google didn't flag any spelling errors :-)
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.
I think you forgot the patch. Oops.
I'd appreciate any suggestions.
At a first glance, this seems like a useful change to me. I have to think about it a bit more.
Of course it would be best if you do the refactoring (provided that you have time), the result is probably optimal. Anyway, you can take a look at the patch and see if it is useful. Thanks! -- Mac
participants (2)
-
Edi Weitz
-
Mac Chan