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

Duplicated content-type response header on error response #27887

Closed
siosio opened this issue Dec 28, 2021 · 4 comments
Closed

Duplicated content-type response header on error response #27887

siosio opened this issue Dec 28, 2021 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@siosio
Copy link

siosio commented Dec 28, 2021

version

  • Spring Boot 2.6.2

code

@SpringBootApplication
class FluxErrorHandlingApplication

fun main(args: Array<String>) {
    runApplication<FluxErrorHandlingApplication>(*args)
}

@Configuration
class Config {
    @Bean
    fun router(handler: Handler) =
        org.springframework.web.reactive.function.server.router {
            GET("/error", handler::handle)
        }
}

@Component
class Handler {
    fun handle(request: ServerRequest): Mono<ServerResponse> {
        throw RuntimeException()
    }
}

result

curl -v localhost:8080/error                                                                                                                                                                             master ✭ ✚ ✱
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /error HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Content-Type: application/json
< Content-Type: application/json
< Content-Length: 131
@snicoll snicoll changed the title Dec 28, 2021
@wilkinsona
Copy link
Member

Here's a more minimal sample that takes Kotlin out of the picture:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;

import reactor.core.publisher.Mono;

import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

@SpringBootApplication
public class Gh29179Application {

    public static void main(String[] args) {
        SpringApplication.run(Gh29179Application.class, args);
    }
    
    
    @Configuration
    class Config {
        @Bean
        RouterFunction<ServerResponse> router(Handler handler) {
            return route(GET("/"), handler::handle);
        }
    }

    @Component
    class Handler {
        Mono<ServerResponse> handle(ServerRequest request) {
            throw new RuntimeException();
        }
    }

}

The duplicate header remains:

$ curl -i localhost:8080
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Content-Type: application/json
Content-Length: 126

{"timestamp":"2022-01-04T16:05:38.216+00:00","path":"/","status":500,"error":"Internal Server Error","requestId":"13e4496c-1"}

@wilkinsona
Copy link
Member

This appears to be a regression in Spring Framework 5.3.14. Downgrading to 5.3.13 results in a single Content-Type header. I believe that 2a5713f is the cause.

@bclozel bclozel transferred this issue from spring-projects/spring-boot Jan 4, 2022
@bclozel bclozel added this to the 5.3.15 milestone Jan 4, 2022
@bclozel bclozel added type: regression A bug that is also a regression in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 4, 2022
@ryanb93
Copy link
Contributor

ryanb93 commented Jan 5, 2022

Combined with istio/istio#30470 this causes clients to receive Content-Type: application/json,application/json;charset=UTF-8 - which clients fail to parse.

@poutsma poutsma self-assigned this Jan 10, 2022
@poutsma
Copy link
Contributor

poutsma commented Jan 10, 2022

The cause here seems to be in NettyHeadersAdapter, which implements putAll by adding headers instead of setting (and overwriting) them.

This bug seems to have been in NettyHeadersAdapter since the type was introduced, and the changes in 2a5713f only brought them to light.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants