Skip to content

missing Content-Length Header in POST requests sent with EXPath HTTP Client #4642

Open
@line-o

Description

@line-o

Describe the bug

When sending a request with an XML body via POST

hc:send-request(
    <hc:request href="http://localhost:8080/exist/apps/test/controller.xq"
        method="POST" timeout="300">
        <hc:body media-type="application/xml" method="xml">
          <some>data</data>
        </hc:body>
    </hc:request>
)

The content-type-header is set but content-length is absent.

This leads to request:get-data() to be empty, when such a request is received by any XQuery module in eXist-6.0.1.

In contrast a simple curl request

curl http://localhost:8080/exist/apps/test/ --data "<some>content</some>" -H "Content-Type:application/xml"

does set the necessary header and therefore the body can be read.

Affected version: current stable (eXist-6.0.1)
This is fixed in 6.1.0 because request:get-data() does receive contents even if conent-length is absent

I was able to trace it down to the class org.expath.httpclient.impl.SinglePartRequestBody. In the setHeaders method only the content-type header is set. This is confirmed for XML-like payloads but judging from the source code it applies to any single body regardless of its type.
The source code I checked was decompiled from http-client-java-1.4.1.jar

Expected behavior

To either the content-length header to be set automatically or for users to be able to set it manually.

To Reproduce

  1. create collection /db/apps/test

  2. create resource /db/apps/test/controller.xq

<request method="{request:get-method()}">
    <headers>
    {
        for $h in request:get-header-names()
        return <header name="{$h}">{ request:get-header($h) }</header>
    }
    </headers>
    <body>{ request:get-data() }</body>
</request>
  1. evaluate the code below in exide
hc:send-request(
    <hc:request href="http://localhost:8080/exist/apps/test/controller.xq"
        method="POST" timeout="300">
        <hc:body media-type="application/xml" method="xml">
          <some>data</data>
        </hc:body>
    </hc:request>
)
  1. in the response the body element is empty
  2. call curl http://localhost:8080/exist/apps/test/ --data "<some>content</some>" -H "Content-Type:application/xml"
  3. in the response the body has the expected contents

Context (please always complete the following information):

  • OS: macOS 12.6
  • eXist-db version: 6.0.1
  • Java Version 1.8.0_352 (Zulu-aarch64)

Additional context

  • How is eXist-db installed? built from source
  • Any custom changes in e.g. conf.xml? none

Metadata

Metadata

Assignees

No one assigned

    Labels

    high prioneeds documentationSignals issues or PRs that will require an update to the documentation repo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions