You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Peter Glasten <pe...@gmail.com> on 2011/08/30 00:21:07 UTC
[users@httpd] how to suppress hard-coded response body in 302 redirect
Hello!
In my Apache module (module AP_MODULE_DECLARE_DATA ... etc etc - low-level
Apache module written in C) I need to return a 302 redirect status with no
body, Content-Length set to zero, and no content-type (this is a third-party
requirement that I cannot change). Apache by default adds hard-coded HTML
body and text/html content type.
Basically, I need just to send "Location: xxx" and "Content-Length: 0"
headers back (with 302 status). I was able to "block" the hard-coded
response body by setting r->header_only to 1, but this seems like a hack,
and ap_http_header_filter (called automatically) removes my Content-Length
header. And Content-Type is still there (text/plain always added, even if I
try to remove it).
I have seen Apache return what I need from a PHP redirect instruction
(mod_php), so I know it is possible (or maybe that's a switch/gateway
messing with me, I don't know). I just can't seem to find a way to do the
same thing using my own module.
Best regards,
Peter
P.S. This is what Apache adds if I don't set r->header_only:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved ...
Re: [users@httpd] how to suppress hard-coded response body in 302 redirect
Posted by Peter Glasten <pe...@gmail.com>.
Thanks, Nick! mod_asis does not really help, as built-in filters mess with
my response (remove content-length: 0 and add default content-type), but at
least I now understand better what's going on. Useful site as well - keep
working on it!
Peter
On Mon, Aug 29, 2011 at 8:14 PM, Nick Kew <ni...@webthing.com> wrote:
> On 29 Aug 2011, at 23:21, Peter Glasten wrote:
>
> > Hello!
> >
> > In my Apache module
>
> Since this is a development question, it would be more on-topic
> for the modules-dev list than here.
>
> > (module AP_MODULE_DECLARE_DATA ... etc etc - low-level Apache module
> written in C) I need to return a 302 redirect status with no body,
> Content-Length set to zero, and no content-type (this is a third-party
> requirement that I cannot change). Apache by default adds hard-coded HTML
> body and text/html content type.
>
> That depends on how/where your module triggers the 302 response.
> If it does so by returning 302 from a pre-handler hook (like, for example,
> mod_alias and mod_rewrite do) then you get what you describe.
> If it works as a handler like CGI or PHP, then you (can easily)
> get what you want and expect. Take a look at mod_asis for a
> startingpoint to do it that way.
>
> Alternatively (and unless your module is doing something v.strange)
> you should be able to delegate the 302 response to the server admin.
> Your module just sets a Location and returns 302, but you can use the
> ErrorDocument directive to customise your response. With a .asis
> ErrorDocument you have full control over the headers.
>
> Note that Content-Length: 0 is redundant, in the absence of anything
> that would lead a client to expect contents.
>
> See also the book: http://www.apachetutor.org/
>
> --
> Nick Kew
>
Re: [users@httpd] how to suppress hard-coded response body in 302 redirect
Posted by Nick Kew <ni...@webthing.com>.
On 29 Aug 2011, at 23:21, Peter Glasten wrote:
> Hello!
>
> In my Apache module
Since this is a development question, it would be more on-topic
for the modules-dev list than here.
> (module AP_MODULE_DECLARE_DATA ... etc etc - low-level Apache module written in C) I need to return a 302 redirect status with no body, Content-Length set to zero, and no content-type (this is a third-party requirement that I cannot change). Apache by default adds hard-coded HTML body and text/html content type.
That depends on how/where your module triggers the 302 response.
If it does so by returning 302 from a pre-handler hook (like, for example,
mod_alias and mod_rewrite do) then you get what you describe.
If it works as a handler like CGI or PHP, then you (can easily)
get what you want and expect. Take a look at mod_asis for a
startingpoint to do it that way.
Alternatively (and unless your module is doing something v.strange)
you should be able to delegate the 302 response to the server admin.
Your module just sets a Location and returns 302, but you can use the
ErrorDocument directive to customise your response. With a .asis
ErrorDocument you have full control over the headers.
Note that Content-Length: 0 is redundant, in the absence of anything
that would lead a client to expect contents.
See also the book: http://www.apachetutor.org/
--
Nick Kew
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org