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 Toby Collett <tc...@plan9.net.nz> on 2009/05/24 11:53:36 UTC

Changing the HTTP response code in a proxy response

Hi all,
I am writing a proxy module that supports a custom extension to the mostly
unimplemented 'Delta coding' RFC. The original standard uses a 226 http
status code for its responses to help deal with HTTP 1.0 web caches
(although this does not completely solve the caching problem).

To be compatible with the delta coding standard I need to be able to set the
226 status code on my responses, but I have having trouble working out how I
would do this in the apache module framework. From what I understand this
needs to be done during header parsing, as the headers are sent to the
downstream server before the body is processed, but I have been unable to
find the right mechanism to do this.

Regards,
Toby Collett

Re: Changing the HTTP response code in a proxy response

Posted by Toby Collett <tc...@plan9.net.nz>.
Hi,
Thanks heaps, I have got that working now. The status string seems to need
to start with the return code (not the version) and need to use the return
code,

r->status = 226;
r->status_line = "226 IM Used";
return OK;

Toby

2009/5/24 Sorin Manolache <so...@gmail.com>

> On Sun, May 24, 2009 at 11:53, Toby Collett <tc...@plan9.net.nz>>
> wrote:
> > Hi all,
> > I am writing a proxy module that supports a custom extension to the
> mostly
> > unimplemented 'Delta coding' RFC. The original standard uses a 226 http
> > status code for its responses to help deal with HTTP 1.0 web caches
> > (although this does not completely solve the caching problem).
> >
> > To be compatible with the delta coding standard I need to be able to set
> the
> > 226 status code on my responses, but I have having trouble working out
> how I
> > would do this in the apache module framework. From what I understand this
> > needs to be done during header parsing, as the headers are sent to the
> > downstream server before the body is processed, but I have been unable to
> > find the right mechanism to do this.
>
> You can do it in your handler without any problem. The output headers
> are written out to the socket by ap_http_header_filter. The call to
> this filter is triggered by passing the first bucket brigade down the
> filter chain. This happens only when you start writing out your
> response. All in all, you can set the status in the handler.
>
> It is very important to set r->status_line as well. Apache checks that
> the return code appears in the status_line. If it doesn't, it gives
> 500 internal server error.
>
> r->status = 226;
> r->status_line = "HTTP/1.0 226 My custom message";
> return 226;
>
> If it doesn't work, try
>
> r->status = 226;
> r->status_line = "HTTP/1.0 226 blabla";
> return OK;
>
> I do not remember exactly how a colleague of mine did it and I don't
> have access to the sources today. I can have a look tomorrow.
>
> S
>
>
>
> >
> > Regards,
> > Toby Collett
> >
>
>
>
> --
> 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?
>



-- 
This email is intended for the addressee only and may contain privileged
and/or confidential information

Re: Changing the HTTP response code in a proxy response

Posted by Sorin Manolache <so...@gmail.com>.
On Sun, May 24, 2009 at 11:53, Toby Collett <tc...@plan9.net.nz> wrote:
> Hi all,
> I am writing a proxy module that supports a custom extension to the mostly
> unimplemented 'Delta coding' RFC. The original standard uses a 226 http
> status code for its responses to help deal with HTTP 1.0 web caches
> (although this does not completely solve the caching problem).
>
> To be compatible with the delta coding standard I need to be able to set the
> 226 status code on my responses, but I have having trouble working out how I
> would do this in the apache module framework. From what I understand this
> needs to be done during header parsing, as the headers are sent to the
> downstream server before the body is processed, but I have been unable to
> find the right mechanism to do this.

You can do it in your handler without any problem. The output headers
are written out to the socket by ap_http_header_filter. The call to
this filter is triggered by passing the first bucket brigade down the
filter chain. This happens only when you start writing out your
response. All in all, you can set the status in the handler.

It is very important to set r->status_line as well. Apache checks that
the return code appears in the status_line. If it doesn't, it gives
500 internal server error.

r->status = 226;
r->status_line = "HTTP/1.0 226 My custom message";
return 226;

If it doesn't work, try

r->status = 226;
r->status_line = "HTTP/1.0 226 blabla";
return OK;

I do not remember exactly how a colleague of mine did it and I don't
have access to the sources today. I can have a look tomorrow.

S



>
> Regards,
> Toby Collett
>



-- 
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?