[tbnl-devel] create-host-dispatch-proxy

Stefan Scholl stesch at no-spoon.de
Tue Jul 27 12:01:48 UTC 2004


Hi!


(defun create-host-dispatch-proxy (host dispatcher)
  "Creates a proxy dispatcher which calls the given DISPATCHER when
the HOST matches."
  (lambda (request)
    (when (and (host request) (string-equal host (host request)))
      (funcall dispatcher request))))


[Function]
create-host-dispatch-proxy host dispatcher => dispatch-fn

A convenience function which will return a dispatcher which calls
the given dispatcher when the host matches.


Purpose:
Use the known functions for creating a dispatcher but add the
feature to match the host first.


Example:
(create-host-dispatch-proxy "www.zappa.test"
                            (create-static-file-dispatcher-and-handler
                             "/tbnl/test/image.jpg"
                             (make-pathname
                              :name "fz" :type "jpg" :version nil
                              :defaults (load-time-value *load-pathname*))
                             "image/jpeg"))

(create-host-dispatch-proxy "www.king.test"
                            (create-static-file-dispatcher-and-handler
                             "/tbnl/test/image.jpg"
                             (make-pathname
                              :name "elvis" :type "jpg" :version nil
                              :defaults (load-time-value *load-pathname*))
                             "image/jpeg"))

This delivers fz.jpg on http://www.zappa.test/tbnl/test/image.jpg
and elvis.jpg on http://www.king.test/tbnl/test/image.jpg



Name has the word "proxy" in it. It's the right name, but it's no
web-proxy as the user would expect. Other name for the function?

The documentation uses the word "dispatcher" two times but one
time it's the one created and the second time it's the one given
in the lambda list. Hard to understand?

Not easy to use in test/test.lisp.



I don't know if this code should be included into TBNL. The list
of convenience functions grows on and could become a bit complex.
I see it more as an example on how to solve a certain problem
when you want to run one lisp image with different (virtual)
webserver addresses.

But feel free to add it anyway.


Regards,
Stefan






More information about the Tbnl-devel mailing list