Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resteasy Reactive adds transfer-encoding header though content-length is present #26464

Closed
Postremus opened this issue Jun 30, 2022 · 3 comments · Fixed by #26467
Closed

Resteasy Reactive adds transfer-encoding header though content-length is present #26464

Postremus opened this issue Jun 30, 2022 · 3 comments · Fixed by #26467
Assignees
Labels
area/resteasy-reactive kind/bug Something isn't working
Milestone

Comments

@Postremus
Copy link
Member

Describe the bug

I want to stream filedownloads. The filesize is already known (stored in db on upload).
The filesize is important to me, since I can use it as content-length header, which allows the browser to show a progress bar for the download instead of just spinning.

e.g.
image

Without the content-length header, browser would simply show a spinning progress.

In resteasy-classic, this worked without problems.
In resteasy-reactive however, I found that the "Transfer-Encoding: Chunked" header is always added to the response when I am stream, even though I manually set content-length.

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public Response hello() {
        String longText = String.join(";", Collections.nCopies(10000000, UUID.randomUUID().toString()));

        byte[] bytes = longText.getBytes(StandardCharsets.UTF_8);

        return Response.ok(new ByteArrayInputStream(bytes), "text/plain")
                .header("Content-length", bytes.length)
                .build();
    }

According to the RFC 2616, this behaviour is not allowed.

Messages must not include both a Content-Length header field and a non-identity transfer-coding. If the message does include a non-identity transfer-coding, the Content-Length must be ignored.

https://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.4.4

Expected behavior

No Transfer-Encoding header is present if a content-length was already manually set.
The response should still be streamed.

Actual behavior

image

How to Reproduce?

Reproducer:
transfer-encoding-clash.zip

  1. mvn quarkus:dev
  2. Open a Browser and the network tools to see response headers
  3. Visit http://localhost:8080/hello
  4. Inspect the response. With resteasy-reactive, it contains both transfer-encoding and content-length.
  5. Change dependency resteasy-reactive to resteasy classic.
  6. Visit http://localhost:8080/hello. Only content-length is now present in the response

Output of uname -a or ver

Microsoft Windows [Version 10.0.19044.1766]

Output of java -version

openjdk 18.0.1 2022-04-19 OpenJDK Runtime Environment Temurin-18.0.1+10 (build 18.0.1+10) OpenJDK 64-Bit Server VM Temurin-18.0.1+10 (build 18.0.1+10, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.10.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: C:\eclipse\tools\java\maven Java version: 18.0.1, vendor: Eclipse Adoptium, runtime: C:\eclipse\tools\java\18 Default locale: de_DE, platform encoding: UTF-8 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Additional information

No response

@Postremus Postremus added the kind/bug Something isn't working label Jun 30, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 30, 2022

/cc @FroMage, @geoand, @stuartwdouglas

@quarkus-bot quarkus-bot bot added area/resteasy-reactive env/windows Impacts Windows machines labels Jun 30, 2022
@geoand geoand removed the env/windows Impacts Windows machines label Jun 30, 2022
@geoand geoand self-assigned this Jun 30, 2022
@geoand
Copy link
Contributor

geoand commented Jun 30, 2022

Thanks for the reproducer. I totally agree the behavior is not correct, looking into it now

@geoand
Copy link
Contributor

geoand commented Jun 30, 2022

#26467 takes care of the issue

geoand added a commit that referenced this issue Jun 30, 2022
Properly ensure that transfer-encoding is not set when content-length exists
@quarkus-bot quarkus-bot bot added this to the 2.11 - main milestone Jun 30, 2022
@gsmet gsmet modified the milestones: 2.11 - main, 2.10.2.Final Jul 4, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 4, 2022
@gsmet gsmet modified the milestones: 2.10.2.Final, 2.7.7.Final Jan 13, 2023
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jan 13, 2023
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/resteasy-reactive kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants