httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre Rothe <>
Subject Re: Change the content-length header for other filters
Date Thu, 22 Dec 2016 13:37:43 GMT

I use mod_ext_filter, which I have modified for my use case. The 
input filter part reads now till the EOS over multiple chunks into a 
brigade, which is then propagated to an external filter (PHP script). 
The script returns the modified POST parameters, which contain 
less bytes then the original request.

These new parameters are moved into a new brigade, which 
mod_ext_filter will return.

The destination for the request is a WebObject application server
which generates the HTML response. My filter should intercept the
request, change it and propagate the modified request to the 
application server (there is a mod_webobjects, which is a bridge
between Apache and WebObjects).

I don't know, how mod_webobjects will read the request content,
but it seems, that my changes on the request are not transparent.
It is not a problem of the transmitted data, it is a length problem
(if I don't change the content length, the request will be processed).

Thanks a lot

 Von:   Sorin Manolache <> 
 An:   <> 
 Gesendet:   12/21/2016 10:52 PM 
 Betreff:   Re: Change the content-length header for other filters 

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é 
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, 

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message