Hi,

I have a camel rest route like the following

rest("/api/test")
        .post()
        .to("direct:test");

from("direct:test").

.toD("http4://localhost/test?bridgeEndpoint=true&throwExceptionOnFailure=false")

.toD("http4://localhost/test2?bridgeEndpoint=true&throwExceptionOnFailure=false");


Trouble occurs when the http4://localhost/test route sets a
content-length header it gets used for http4://localhost/test2.  There
are some web servers that use that header to determine request size
which if it never gets to the needed length will never close and after a
while timeout.  This happens despite content-length being in the
HttpHeaderFilterStrategy list because in the HttpProducer class there is
code like this.  So an input stream will still use the header.

// fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this
is the fallback
                        InputStream is =
in.getMandatoryBody(InputStream.class);
                        String length =
in.getHeader(Exchange.CONTENT_LENGTH, String.class);
                        InputStreamEntity entity = null;
                        if (ObjectHelper.isEmpty(length) ) {
                            entity = new InputStreamEntity(is, -1);
                        } else {
                            entity = new InputStreamEntity(is,
Long.parseLong(length));
                        }
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }

I'm assuming there are cases where I might want to explicitly provide
the content-length to the request entity.  But I'd like to be able to
turn it off so it always falls back to -1 (chunked).

I'm working around the issue by doing this:

from("direct:test").

.toD("http4://localhost/test?bridgeEndpoint=true&throwExceptionOnFailure=false")

.setHeader("Content-Length", constant(""))

.toD("http4://localhost/test2?bridgeEndpoint=true&throwExceptionOnFailure=false");

But I'd like to suggest creating a more global way to ignore the
Content-Length header:

// fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this
is the fallback
                        InputStream is =
in.getMandatoryBody(InputStream.class);
                        String length =
in.getHeader(Exchange.CONTENT_LENGTH, String.class);
                        InputStreamEntity entity = null;
                        if (ObjectHelper.isEmpty(length) ||
getEndpoint().getComponent().isForceChunkedRequestEntity()) {
                            entity = new InputStreamEntity(is, -1);
                        } else {
                            entity = new InputStreamEntity(is,
Long.parseLong(length));
                        }
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }


Thoughts on this approach?  How are other folks dealing with this? 
Happy to work on a contribution/patch but I wanted to discuss before
creating a jira. 


- Bob

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to