Skip to content

[Bug] NettyHeadersAdapter duplicates values when header case is mixed #33931

Closed as not planned
@mtheos

Description

@mtheos

Hello Spring maintainers,

I've found a bug in the NettyHeadersAdapter that causes it to duplicate header values when the string case is mixed up between entries.

This arises because the adapter iterates through the underlying entries using a case-insensitive method to get the values.

DefaultHttpHeaders headers;
for (var n : headers.names()) {       <-- case sensitive
  for (var v : headers.getAll(n)) {   <-- case insensitive
    System.out.println(n + "=" + v);
  }
}

I've reproduced this on 6.2.0
Reproducer:

var headers = new DefaultHttpHeaders();
var adapter = new Netty5HeadersAdapter(headers);  // Also with Netty4
adapter.add("foo-bar", "one");
adapter.add("Foo-Bar", "two");
adapter.add("fOO-bar", "three");
for (var e : adapter.entrySet()) {
   System.out.println(e.getKey() + "=" + e.getValue());
}

/*
Output:
foo-bar=[one, two, three]
Foo-Bar=[one, two, three]
fOO-bar=[one, two, three]
*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions