Skip to content

Content-length set to -1 when it is not sent from the server #4965

@kjezek

Description

@kjezek

When a request is triggered to a server endpoint, which does not provide Content-length, the ApacheConnector adds Content-length with the value equals to -1.

The problematic code is here:

if (headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
}

It should probably be:

                if (headers.get(HttpHeaders.CONTENT_LENGTH) == null && entity.getContentLength() > 0) {
                    headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
                }

The main problem is that the ApacheConnector generates the header value, which is against the specification, i.e. when the content length is not know, this header should not be provided at all, not provided with a negative value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions