[hunchentoot-devel] Virtual hosts support using *META-DISPATCHER*

Hi all, I'm in the process of migrating a Web app from Portable Allegroserve to Hunchentoot (0.10), and I had a question about implementing virtual hosts by overriding the *META-DISPATCHER* function binding. Here's what I have so far: ---------------- (defvar *vhost-dispatch-table-map* (make-hash-table :test 'string=)) (defun vhost-meta-dispatcher (server) (declare (ignore server)) (or (gethash (hunchentoot:host) *vhost-dispatch-table-map*) *dispatch-table*)) (defun vhost-set-dispatch-table (hosts dispatch-table &key defaultp) (dolist (hostname (pg:mklist hosts)) (setf (gethash hostname *vhost-dispatch-table-map*) dispatch-table)) (when defaultp (setq *dispatch-table* dispatch-table))) (setq hunchentoot:*meta-dispatcher* 'vhost-meta-dispatcher) ---------------- Now, I'm able to return different *DISPATCH-TABLE* bindings based on the hostname, like so: ---------------- (vhost-set-dispatch-table "foo.bar.com" (list (hunchentoot:create-folder-dispatcher-and-handler "/assets/" #p"/var/www/foo.bar.com/assets/"))) (vhost-set-dispatch-table "quux.bar.com" (list (hunchentoot:create-folder-dispatcher-and-handler "/assets/" #p"/var/www/quux.bar.com/assets/"))) ---------------- Are there any problems in subverting the *META-DISPATCHER* binding this way? Is there a better alternative? Thanks. -ram

On Sat, 28 Jul 2007 21:16:57 -0700, "Ram Krishnan" <rkris@kriyative.net> wrote:
Are there any problems in subverting the *META-DISPATCHER* binding this way? Is there a better alternative?
Looks OK to me. That (virtual host support) was actually one of the reasons why *META-DISPATCHER* is there. Cheers, Edi.

Perfect. Thanks for the follow up. Also, thanks Edi for Hunchentoot and all the other excellent Lisp packages you've contributed. Regards, -ram On 7/29/07, Edi Weitz <edi@agharta.de> wrote:
On Sat, 28 Jul 2007 21:16:57 -0700, "Ram Krishnan" <rkris@kriyative.net> wrote:
Are there any problems in subverting the *META-DISPATCHER* binding this way? Is there a better alternative?
Looks OK to me. That (virtual host support) was actually one of the reasons why *META-DISPATCHER* is there.
Cheers, Edi. _______________________________________________ tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel

Perhaps I'm missing something, but why would using *meta-dispatcher* be preferred to, say, just setting the server-dispatch-table? I've been using virtual hosts without *meta-dispatcher* and I'd like to minimize the global changes that would change the behavior of, say, other servers that one might bring up in the same instance. Thanks, Cyrus On Jul 29, 2007, at 2:37 PM, Ram Krishnan wrote:
Perfect. Thanks for the follow up.
Also, thanks Edi for Hunchentoot and all the other excellent Lisp packages you've contributed.
Regards,
-ram
On 7/29/07, Edi Weitz <edi@agharta.de> wrote: On Sat, 28 Jul 2007 21:16:57 -0700, "Ram Krishnan" < rkris@kriyative.net> wrote:
Are there any problems in subverting the *META-DISPATCHER* binding this way? Is there a better alternative?
Looks OK to me. That (virtual host support) was actually one of the reasons why *META-DISPATCHER* is there.
Cheers, Edi. _______________________________________________ tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
_______________________________________________ tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel

On Sun, 5 Aug 2007 17:07:38 -0700, Cyrus Harmon <ch-tbnl@bobobeach.com> wrote:
Perhaps I'm missing something, but why would using *meta-dispatcher* be preferred to, say, just setting the server-dispatch-table? I've been using virtual hosts without *meta-dispatcher* and I'd like to minimize the global changes that would change the behavior of, say, other servers that one might bring up in the same instance.
I'd say that your approach is fine as well. I'd prefer using separate dispatch tables for stylistic reasons, but as usual TMTOWTDI.
participants (3)
-
Cyrus Harmon
-
Edi Weitz
-
Ram Krishnan