spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

AbstractProxyExchange takes into account MediaType parameters

Open jerolba opened this issue 4 months ago • 0 comments

Describe the bug

AbstractProxyExchange compares response MediaType with configured StreamingMediaTypes using equals method that takes into account MediaType parameters.

In this code:

if (properties.getStreamingMediaTypes().contains(clientResponse.getHeaders().getContentType())) {

a response with content type text/event-stream;charset=utf-8 is not considered as a streaming media type

A better way of comparing MediaType without considering parameters is using MediaType::equalsTypeAndSubtype method.

The code can be changed to something like this:

if (isStreamingMediaType(clientResponse.getHeaders().getContentType())) {

implementing a new method:

  private boolean isStreamingMediaType(MediaType mediaType) {
    return properties.getStreamingMediaTypes().stream().anyMatch(streameable -> streamable.equalsTypeAndSubtype(mediaType));
  }

The specification of Server-Sent Events implicitly states that the ContentType is text/event-stream and that the charset is UTF-8, but some servers are including it explicitly in their response, breaking the streaming feature in Spring Cloud Gateway.

Sample No

jerolba avatar Oct 13 '25 18:10 jerolba