Skip to content

AbstractProxyServlet.filterServerResponseHeader returns existing valueΒ #15548

Closed

Description

@rob-spoor

Jetty version(s)
This started in Jetty 12.1.12. In version 12.1.11 this issue does not occur.

Jetty Environment
jetty-ee9-proxy, jetty-ee10-proxy, jetty-ee11-proxy

HTTP version
Any

Java version/vendor (use: java -version)

openjdk version "17.0.20" 2026-07-21
OpenJDK Runtime Environment Temurin-17.0.20+8 (build 17.0.20+8)
OpenJDK 64-Bit Server VM Temurin-17.0.20+8 (build 17.0.20+8, mixed mode, sharing)

OS type/version
Windows 11

Description
Jetty 12.1.12 deprecated the existing AbstractProxyServlet.filterServerResponseHeader method and created an overload that works not with strings but with HttpField. It calls the deprecated method and then calls field.withValue. If the filtered value is different, this doesn't replace the value but adds to it. It also doesn't handle null return values correctly. This behavior is very different from version 12.1.12. I see two better implementations. The first:

String existingValue = field.getValue();
String filteredValue = filterServerResponseHeader(clientRequest, serverResponse, field.getName(), existingValue);
if (filteredValue == null) {
    return null;
}
if (existingValue.equals(filteredValue) {
    return field;
}
return new HttpField(field.getHeader(), field.getName(), filteredValue);

The second is the same except for the final line:

return field.withoutValue(existingValue).withValue(filteredValue);

How to reproduce?
Create a subclass of AbstractProxyServlet. Override the deprecated filterServerResponseHeader method to return something different for the location header, and `null`` for the date header:

if ("Location".equalsIgnoreCase(headerName)) {
    return "http://localhost/proxy";
}
if ("Date".equalsIgnoreCase(headerName)) {
    return null;
}
return super.filterServerResponseHeader(clientRequest, serverResponse, headerName, headerValue);

Proxy to a URL that returns Location and Date headers.

In version 12.1.11 the client should see only one Location header value and no Date header.
In version 12.1.12 the client will see two Location header values (the original and the filtered one), and two Date header values (the original one and "null").

Activity

  1. rob-spoor commented on Aug 5, 2026

    @rob-spoor
    Author

    A possible extra option: give HttpField an extra withSingleValue(String value) method that does this:

    if (this.value.equals(value)) {
        return this;
    }
    return new HttpField(getHeader(), _name, value);

    Then filterServerResponseHeader can replace the last two returns with a single return field.withSingleValue(filteredValue) call. The null check remains necessary though.

  2. moved this to πŸ— In progress in FROZEN Jetty 12.1.13on Aug 31, 2026
  3. self-assigned this
    on Aug 31, 2026
  4. linked a pull request that will close this issueFix #15548 filter server response header #15685on Aug 31, 2026
  5. added theissue type on Aug 31, 2026
  6. removed theissue type on Aug 31, 2026
  7. moved this from πŸ— In progress to βœ… Done in FROZEN Jetty 12.1.13on Aug 31, 2026
  8. added a commit that references this issue on Aug 31, 2026
    da94c50
  9. added a commit that references this issue on Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugFor general bugs on Jetty side

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions