Re: Redirection not working with nethttpd
Jake Donham <[email protected]> Tue, 11 Aug 2009 10:16:04 -0700
| Newsgroups | gmane.comp.lang.ocaml.lib.net.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Paolo,
I think you can fix it by giving a full URL in the Location header in this code:
let e = cgi#environment in
e#set_output_header_fields [];
e#set_status `Found;
e#set_output_header_field "Location" "/redir";
cgi#out_channel#commit_work ();
If the Location header starts with "/", Nethttpd tries to do an
"internal" redirect--that is, to rewrite the request and process it
directly, instead of returning a 302 response to the client.
See generate_response in nethttpd_services.ml, where Redirect_response
is raised if the location starts with "/". This is finally handled in
process_request of nethttpd_reactor.ml (it has been turned into
Redirect_response_legal) which rewrites the request and processes it
again.
The exception you see is raised in nethttpd_reactor.ml, apparently
because the response has already been partially written. Possibly if
you really want an internal redirect you aren't supposed to commit the
channel?
Jake
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july