You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by cronfy <cr...@gmail.com> on 2010/12/26 09:58:58 UTC
Sending http headers for 3xx responses
Hello.
I am trying to create a module that would send some response headers related
to request. I've taken mod_expires code and adapted it for my needs.
Everything works fine for 200 responses, but when response is "304 Not
Modified", my headers do not appear there.
I tried to set r->headers_out and r->err_headers_out, but it does not work.
The filter function runs on every request indeed, I checked it with debug
right near
t = r->headers_out;
apr_table_set(t, "X-Process-Info", msg);
But X-Process-Info: is not in the output still. What am I missing?
Thanks in advance!
--
// cronfy
Re: Sending http headers for 3xx responses
Posted by Nick Kew <ni...@webthing.com>.
On 27 Dec 2010, at 12:30, cronfy wrote:
>
>
> > Thanks, I tried it. Currently filter function looks like this:
> >
> > static apr_status_t procinfo_filter(ap_filter_t *f,
> > apr_bucket_brigade *b)
>
> Why are you doing this in a filter? You should be manipulating
> the response *body* in a filter, but the *headers* in a processing hook.
>
> I did not know about that. As I said, I've taken code from mod_expires, and it modifies headers via filter.
> What hook should I use to manipulate headers *AFTER* content generation was finished?
The headers commonly get sent to the client *BEFORE* content generation is finished.
That's one reason it's rarely a good idea to manipulate them in a filter.
Though with the code you posted it doesn't look like *the* problem, provided
your filter is ahead of HTTP in the filter chain.
> > With no luck for 3xx responses. It works even for 404 Not Found, but not for 3xx.
> Where does the 3xx come from? Is it a script, or something using the
> same (util_script) processing path like mod_asis? Or a hooked function?
>
> I tested 304 response for usual static file, and 304 response generated by php script. Headers were not set in both cases.
I guess where 304 runs legitimately, it knows there's no response body to filter
(because it's forbidden by the HTTP spec), so it's not running content filters at all.
But I couldn't say for sure OTTOMH.
--
Nick Kew
Re: Sending http headers for 3xx responses
Posted by cronfy <cr...@gmail.com>.
> Thanks, I tried it. Currently filter function looks like this:
> >
> > static apr_status_t procinfo_filter(ap_filter_t *f,
> > apr_bucket_brigade *b)
>
> Why are you doing this in a filter? You should be manipulating
> the response *body* in a filter, but the *headers* in a processing hook.
>
I did not know about that. As I said, I've taken code from mod_expires, and
it modifies headers via filter.
What hook should I use to manipulate headers *AFTER* content generation was
finished?
> With no luck for 3xx responses. It works even for 404 Not Found, but not
> for 3xx.
> Where does the 3xx come from? Is it a script, or something using the
> same (util_script) processing path like mod_asis? Or a hooked function?
>
I tested 304 response for usual static file, and 304 response generated by
php script. Headers were not set in both cases.
BTW, this should be on the modules-dev list.
>
>
Thanks and sorry, I subscribed it and will go there with further questions.
--
// cronfy
Re: Sending http headers for 3xx responses
Posted by Nick Kew <ni...@webthing.com>.
On 26 Dec 2010, at 09:35, cronfy wrote:
>
> Thanks, I tried it. Currently filter function looks like this:
>
> static apr_status_t procinfo_filter(ap_filter_t *f,
> apr_bucket_brigade *b)
Why are you doing this in a filter? You should be manipulating
the response *body* in a filter, but the *headers* in a processing hook.
> With no luck for 3xx responses. It works even for 404 Not Found, but not for 3xx.
Where does the 3xx come from? Is it a script, or something using the
same (util_script) processing path like mod_asis? Or a hooked function?
BTW, this should be on the modules-dev list.
--
Nick Kew
Re: Sending http headers for 3xx responses
Posted by cronfy <cr...@gmail.com>.
Thanks, I tried it. Currently filter function looks like this:
static apr_status_t procinfo_filter(ap_filter_t *f,
apr_bucket_brigade *b)
{
_DBG("IN FILTER", 0);
request_rec *r;
apr_table_t *t;
char *msg;
r = f->r;
procinfo_config_t *cf = ap_get_module_config(r->connection->conn_config,
&procinfo_module);
msg = apr_psprintf(r->pool, "%s", "test");
t = r->headers_out;
apr_table_set(t, "X-Process-Info", msg);
t = r->err_headers_out;
apr_table_set(t, "X-Process-Info", msg);
ap_remove_output_filter(f);
return ap_pass_brigade(f->next, b);
}
With no luck for 3xx responses. It works even for 404 Not Found, but not for
3xx.
> 3xx is considered an "error" as far as headers are concerned, so use the
> err_headers
>
> Issac
>
>
> On 26/12/2010 10:58, cronfy wrote:
> > Hello.
> >
> > I am trying to create a module that would send some response headers
> > related to request. I've taken mod_expires code and adapted it for my
> > needs. Everything works fine for 200 responses, but when response is
> > "304 Not Modified", my headers do not appear there.
> >
> > I tried to set r->headers_out and r->err_headers_out, but it does not
> > work. The filter function runs on every request indeed, I checked it
> > with debug right near
> >
> > t = r->headers_out;
> > apr_table_set(t, "X-Process-Info", msg);
> >
> > But X-Process-Info: is not in the output still. What am I missing?
> >
> > Thanks in advance!
> >
> > --
> > // cronfy
>
>
--
// cronfy
Re: Sending http headers for 3xx responses
Posted by Issac Goldstand <ma...@beamartyr.net>.
3xx is considered an "error" as far as headers are concerned, so use the
err_headers
Issac
On 26/12/2010 10:58, cronfy wrote:
> Hello.
>
> I am trying to create a module that would send some response headers
> related to request. I've taken mod_expires code and adapted it for my
> needs. Everything works fine for 200 responses, but when response is
> "304 Not Modified", my headers do not appear there.
>
> I tried to set r->headers_out and r->err_headers_out, but it does not
> work. The filter function runs on every request indeed, I checked it
> with debug right near
>
> t = r->headers_out;
> apr_table_set(t, "X-Process-Info", msg);
>
> But X-Process-Info: is not in the output still. What am I missing?
>
> Thanks in advance!
>
> --
> // cronfy