Edi Weitz wrote:
FYI, I'm currently re-factoring the code (and changing parts of the API while I'm at it).
Here is a small API change that's been sitting in my queue for awhile:
REDIRECT currently builds a full URL out of the script name, the host, and one of two hard-coded protocols. This is useful when you are redirecting to another HTTP/S URL on your site.
Often, however, I have cases where I already know the full URL, either because the user has given it too me, or because I have it stored in a database. It seems wasteful and hazardous to break the URL apart only to put it back together again. Also, there are times when I need to redirect to protocols other than http:// or https:// (such as ftp:// or even sip://).
Therefore I propose that a lower level function be slid underneath REDIRECT and exported. I've tentatively called this REDIRECT-URL.
Cheers,
-- Travis
Sun Oct 8 23:02:53 EDT 2006 Travis Cross tc@traviscross.com * Added exported function REDIRECT-URL. diff -rN -u old-hunchentoot/modlisp.lisp new-hunchentoot/modlisp.lisp --- old-hunchentoot/modlisp.lisp 2006-10-08 23:04:56.000000000 -0400 +++ new-hunchentoot/modlisp.lisp 2006-10-08 23:04:56.000000000 -0400 @@ -210,6 +210,20 @@ (rfc-1123-date)) (values))
+(defun redirect-url (url &key add-session-id permanently) + "Redirects the browser to the resource URL. Adds a session ID if +ADD-SESSION-ID is true. If PERMANENTLY is true, a 301 request is +sent to the browser, otherwise a 302." + (when add-session-id + (setq url (add-cookie-value-to-url url :replace-ampersands-p nil))) + (setf (header-out "Location") + url + (return-code *reply*) + (if permanently + +http-moved-permanently+ + +http-moved-temporarily+)) + (throw 'handler-done nil)) + (defun redirect (script-name &key (host (host *request*) host-provided-p) (protocol (if (ssl-session-id *request*) @@ -227,15 +241,9 @@ ((:http) "http") ((:https) "https")) host script-name))) - (when add-session-id - (setq url (add-cookie-value-to-url url :replace-ampersands-p nil))) - (setf (header-out "Location") - url - (return-code *reply*) - (if permanently - +http-moved-permanently+ - +http-moved-temporarily+)) - (throw 'handler-done nil))) + (redirect-url url + :add-session-id add-session-id + :permanently permanently)))
(defun require-authorization (&optional (realm "Hunchentoot")) (setf (header-out "WWW-Authenticate") diff -rN -u old-hunchentoot/packages.lisp new-hunchentoot/packages.lisp --- old-hunchentoot/packages.lisp 2006-10-08 23:04:56.000000000 -0400 +++ new-hunchentoot/packages.lisp 2006-10-08 23:04:56.000000000 -0400 @@ -174,6 +174,7 @@ :raw-post-data :real-remote-addr :recompute-request-parameters + :redirect-url :redirect :referer :remote-addr