You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Juhani Connolly <Ju...@ninja.co.jp> on 2009/01/07 07:14:38 UTC

Forcing additional headers with Location: redirect

I'm currently working on modifying a php based application into an apache 
module.

The short of it is that I want to send a Location header with a 0 content 
length message and headers for cache-control and pragma.
Setting the headers, and returning HTTP_MOVED_TEMPORARILY the additional 
headers are stripped and the default message is sent.
Using ErrorDocument in my httpd.conf to use a 0 length file, the content 
length is correctly set to 0, but even the Location header gets stripped.
I am pretty sure the cause of my issue is unrelated to the additional 
headers, just needing me to send no content which is confusing the problem 
handsets. How can I cause this behaviour?

For anyone interested, the background of the situation, some source after 
the background:

In addition to logging an access to an image, this module will redirect the 
request based on some parameters to a different server. The php version 
would send Location, pragma: no-cache, cache-control: no-cache, 
must-revalidate and 0 content length, which worked perfectly for all 
clients.
Within the module I have set the location header as well as the pragma and 
cache-control, however only the location will go through, and the default 
302 message is sent. This is not generally a problem, except for with one of 
the local mobile phone handset manufacturers which fails to redirect the 
image correctly claiming a bad image.
Thus I am attempting to emulate the behaviour of the php, being unsure of 
which part is causing the problem. Most likely it would be the content being 
sent confusing the handset. Honestly I'd like to just ignore the particular 
manufacturer, but this is not an option.

Some source(stripped down to the essentials... In the actual version there's 
error handling and whatnot):

 curl_easy_setopt(hCurl, CURLOPT_URL, adUrl);  // url to get the redirect 
location from
 curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, &outUrl);
 curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, outUrlWrite);

 if(curl_easy_perform(hCurl) == 0)
 {
  apr_table_setn(r->headers_out, "Location", outUrl);
 }

 r->content_type = CONTENT_TYPE_MOBILE;

 apr_table_setn(r->headers_out, "Cache-Control", "no-cache, 
must-revalidate");
 apr_table_setn(r->headers_out, "Pragma", "no-cache");

 curl_easy_cleanup(hCurl);

 return HTTP_MOVED_TEMPORARILY; 


Re: Forcing additional headers with Location: redirect

Posted by Juhani Connolly <Ju...@ninja.co.jp>.
Thank you, that worked fine, I'm now getting the headers I intended.

----- Original Message ----- 
From: "Sorin Manolache" <so...@gmail.com>
To: <mo...@httpd.apache.org>
Sent: Wednesday, January 07, 2009 4:59 PM
Subject: Re: Forcing additional headers with Location: redirect

> 
> Use r->err_headers_out instead of r->headers_out. If it does not work,
> there's a longer and more complicated solution based on
> insert_error_filter. Come back for details if err_headers_out does not
> solve the problem.
> 
> --
> Sorin
> 
> -- 
> A: Because it reverses the logical flow of conversation.
> Q: Why is top-posting frowned upon?
> A: Top-posting.
> Q: What is the most annoying thing in e-mail?
> 
>

Re: Forcing additional headers with Location: redirect

Posted by Sorin Manolache <so...@gmail.com>.
On Wed, Jan 7, 2009 at 07:14, Juhani Connolly <Ju...@ninja.co.jp> wrote:
> I'm currently working on modifying a php based application into an apache
> module.
>
> The short of it is that I want to send a Location header with a 0 content
> length message and headers for cache-control and pragma.
> Setting the headers, and returning HTTP_MOVED_TEMPORARILY the additional
> headers are stripped and the default message is sent.
> Using ErrorDocument in my httpd.conf to use a 0 length file, the content
> length is correctly set to 0, but even the Location header gets stripped.
> I am pretty sure the cause of my issue is unrelated to the additional
> headers, just needing me to send no content which is confusing the problem
> handsets. How can I cause this behaviour?
>
> For anyone interested, the background of the situation, some source after
> the background:
>
> In addition to logging an access to an image, this module will redirect the
> request based on some parameters to a different server. The php version
> would send Location, pragma: no-cache, cache-control: no-cache,
> must-revalidate and 0 content length, which worked perfectly for all
> clients.
> Within the module I have set the location header as well as the pragma and
> cache-control, however only the location will go through, and the default
> 302 message is sent. This is not generally a problem, except for with one of
> the local mobile phone handset manufacturers which fails to redirect the
> image correctly claiming a bad image.
> Thus I am attempting to emulate the behaviour of the php, being unsure of
> which part is causing the problem. Most likely it would be the content being
> sent confusing the handset. Honestly I'd like to just ignore the particular
> manufacturer, but this is not an option.
>
> Some source(stripped down to the essentials... In the actual version there's
> error handling and whatnot):
>
> curl_easy_setopt(hCurl, CURLOPT_URL, adUrl);  // url to get the redirect
> location from
> curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, &outUrl);
> curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, outUrlWrite);
>
> if(curl_easy_perform(hCurl) == 0)
> {
>  apr_table_setn(r->headers_out, "Location", outUrl);
> }
>
> r->content_type = CONTENT_TYPE_MOBILE;
>
> apr_table_setn(r->headers_out, "Cache-Control", "no-cache,
> must-revalidate");
> apr_table_setn(r->headers_out, "Pragma", "no-cache");
>
> curl_easy_cleanup(hCurl);
>
> return HTTP_MOVED_TEMPORARILY;
>

Use r->err_headers_out instead of r->headers_out. If it does not work,
there's a longer and more complicated solution based on
insert_error_filter. Come back for details if err_headers_out does not
solve the problem.

--
Sorin

-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?