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

fix: improve media type comparison for streaming responses #3948

Open jerolba opened this issue 2 months ago • 0 comments

Fix #3948

Improves the media type comparison logic for determining when to use streaming response handling by implementing proper type and subtype matching instead of relying on exact media type equality.

This fix addresses scenarios where streaming responses include charset or other parameters in their Content-Type headers, ensuring they are properly handled with the streaming copy mechanism that includes appropriate flushing.

Problem

The previous implementation used List.contains() to check if a response's content type matches any of the configured streaming media types. This approach failed when the actual media type included parameters (e.g., text/event-stream;charset=UTF-8) because it relied on exact MediaType object equality rather than semantic type/subtype matching.

Solution

  • Replaced the direct contains() check with a new isStreamingMediaType() helper method
  • Implemented proper media type comparison using MediaType.equalsTypeAndSubtype()
  • Added comprehensive test coverage for media types with parameters

jerolba avatar Nov 03 '25 19:11 jerolba