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 André Rothe <an...@zks.uni-leipzig.de> on 2016/12/21 21:10:00 UTC
Change the content-length header for other filters
Hi,
I have a filter, which changes the content length of a POST request.
There are some key-value-pairs of the request, which the filter removes
before other filters process the request.
But after my filter completes the request processing, I'll get:
Sending error response: The request contained fewer content data than
specified by the content-length header
I have tried to change the header key "Content-Length" and set the
new value like:
apr_table_set(f->r->headers_in, "Content-Length",
apr_psprintf(f->r->pool, "%ld", len));
but it has no effect outside of my filter. The incoming request has a
content length of 1107 bytes. I modify the bucket brigade and it
contains at the end of my filter code only 1074 bytes (which is also
stored into "len").
What can I do to send the new content length along the filter chain?
Thank you
Andr�
Re: Change the content-length header for other filters
Posted by Nick Kew <ni...@apache.org>.
On Wed, 2016-12-21 at 22:10 +0100, Andr� Rothe wrote:
> But after my filter completes the request processing, I'll get:
>
> Sending error response: The request contained fewer content data than
> specified by the content-length header
Sorin's reply is part of the story, and may or may not be useful
in your case.
The basic issue you have to consider is that the headers arrive before
the body, and a handler that cares about Content-Length is likely
to have read it before your filter has reset it.
The alternative - read and buffer the entire body before starting
to process it - becomes hopelessly inefficient for large requests.
There's some discussion of the issue in the mod_proxy docs,
as mod_proxy has an option to support HTTP/1.0 backends that
need an explicit Content-Length.
--
Nick Kew
Re: Change the content-length header for other filters
Posted by Sorin Manolache <so...@gmail.com>.
On 2016-12-21 22:10, Andr� Rothe wrote:
> Hi,
>
> I have a filter, which changes the content length of a POST request.
> There are some key-value-pairs of the request, which the filter removes
> before other filters process the request.
>
> But after my filter completes the request processing, I'll get:
>
> Sending error response: The request contained fewer content data than
> specified by the content-length header
>
> I have tried to change the header key "Content-Length" and set the
> new value like:
>
> apr_table_set(f->r->headers_in, "Content-Length",
> apr_psprintf(f->r->pool, "%ld", len));
>
> but it has no effect outside of my filter. The incoming request has a
> content length of 1107 bytes. I modify the bucket brigade and it
> contains at the end of my filter code only 1074 bytes (which is also
> stored into "len").
>
> What can I do to send the new content length along the filter chain?
>
> Thank you
> Andr�
Hello,
Could you please give us more details about how the body of the post
request is read? Is it read in a third-party handler? Is is read by a
standard apache module such as mod_proxy? If it's a third-party handler,
do you happen to have the code?
Why I'm asking: because it may happen that the reader (i.e. the code
that triggers the chain of input filters) reads first the Content-Length
header and then attempts to read N bytes, where N is the value of the
Content-Length filter. In this case, it is no use to set Content-Length
in your filter because anyway the reader has read the value of the
Content-Length header before your filter had the opportunity to change it.
A well-behaved reader should read until it finds an EOS bucket in the
retrieved brigade. It should not rely on Content-Length. A trivial
example why it should not use Content-Length is request body
compression. A reader would get the brigade filtered by the INFLATE
filter of mod_deflate, which contains many more bytes than indicated by
Content-Length as this header contains the size of the compressed body.
Best regards,
Sorin