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

Multiple header when use ResponseEntity.status(200).header("content-type","xxx") #24481

Closed
liangyuanpeng opened this issue Mar 22, 2022 · 7 comments
Assignees
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working triage/wontfix This will not be worked on

Comments

@liangyuanpeng
Copy link

liangyuanpeng commented Mar 22, 2022

Describe the bug

Return multiple header of content-type

Expected behavior

Only one header of Content-Type and rewrite it when we use some code like that ResponseEntity.status(200).header("content-type","application/jsonhello").build();

Actual behavior

Multiple header of Content-Type

How to Reproduce?

Some simple code, use spring web for API.

 @GetMapping("/hello")
    public ResponseEntity<BaseResponse> hello(){
        return ResponseEntity.status(200).header("content-type","application/jsonhello").build();
    }

Run the application and request this API.

oem@lan:~$ curl -X GET http://localhost:8080/hello -I
HTTP/1.1 200 OK
Content-Type: application/json
Content-Type: application/jsonhello
content-length: 0

Output of uname -a or ver

Linux lan 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.13" 2021-10-19 OpenJDK Runtime Environment GraalVM CE 20.3.4 (build 11.0.13+7-jvmci-20.3-b24) OpenJDK 64-Bit Server VM GraalVM CE 20.3.4 (build 11.0.13+7-jvmci-20.3-b24, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

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

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: /home/oem/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4 Java version: 11.0.13, vendor: Eclipse Adoptium, runtime: /home/oem/soft/jdk-11.0.13+8 Default locale: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "5.4.0-58-generic", arch: "amd64", family: "unix"

Additional information

quarkus.platform.version 2.7.3.Final
@liangyuanpeng liangyuanpeng added the kind/bug Something isn't working label Mar 22, 2022
@geoand geoand added area/spring Issues relating to the Spring integration and removed triage/needs-triage labels Mar 23, 2022
@geoand geoand self-assigned this Mar 23, 2022
geoand added a commit to geoand/quarkus that referenced this issue Mar 23, 2022
@geoand
Copy link
Contributor

geoand commented Mar 23, 2022

I was not able to reproduce this problem and even added a test in #24489 to validate that we follow the proper behavior.

@liangyuanpeng
Copy link
Author

liangyuanpeng commented Mar 23, 2022

@geoand Thanks for your work and quick reply. I have try to do the same test for my code and unit test working for me, but i really got the two same header when i after started application. now, my quarkus version is 2.7.5.Final.

My test code:

    @Test
    public void headerTest(){
        given()
                .when().get("/hello")
                .then()
                .statusCode(200)
                .header("content-type","application/jsontest")
                .header("custom-header","value");
    }

API method code:

    @GetMapping("/hello")
    public ResponseEntity<BaseResponse> hello(){
        return ResponseEntity.status(200).contentType(org.springframework.http.MediaType.valueOf("application/jsontest")).header("custom-header","value").build();
    }

Call API

lan@yunhorn:~$ curl -X GET http://localhost:8080/hello -I
HTTP/1.1 200 OK
custom-header: value
Content-Type: application/json
Content-Type: application/jsontest
content-length: 0

@geoand
Copy link
Contributor

geoand commented Mar 23, 2022

Thanks, let me check

geoand added a commit to geoand/quarkus that referenced this issue Mar 23, 2022
@geoand
Copy link
Contributor

geoand commented Mar 23, 2022

I updated the PR to use your latest code and again everything works as expected

@liangyuanpeng
Copy link
Author

liangyuanpeng commented Mar 23, 2022

Yes,unit test is working, but request to the really API, it in the wrong side.

This is the min reproduce code.
code-with-quarkus.zip

  1. quarkus dev (or other command ) start application
  2. request api /hello and check the header. curl -X GET http://localhost:8080/hello -I

@geoand
Copy link
Contributor

geoand commented Mar 23, 2022

Now I see what the confusion is. You are using quarkus-resteasy-jackson while I am using quarkus-resteasy-reactive-jackson.
I don't think we will be providing any fixes for Spring Web support on RESTEasy Classic, so best switch to RESTEasy Reactive.

Thanks

@geoand geoand added the triage/wontfix This will not be worked on label Mar 23, 2022
@geoand geoand closed this as completed Mar 23, 2022
@liangyuanpeng
Copy link
Author

Thanks for your confirmed, Change quarkus-resteasy-jackson to quarkus-resteasy-reactive-jacksonand it working for me.

geoand added a commit that referenced this issue Mar 23, 2022
Add test to make sure ResponseEntity content type takes precedence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working triage/wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants