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