Skip to content

Request headers whose value matches the request URI host are dropped from curl and HTTPie snippets #1053

Description

@harrisleesh

The HostHeaderFilter in CliOperationRequest is meant to elide only an implicit Host header, but its allow(String name, List<String> value) implementation never inspects the header name:

@Override
public boolean allow(String name, List<String> value) {
    return !(value.isEmpty() || this.getImplicitHostHeader().equals(value.get(0)));
}

The filter is applied to every header, so any header whose first value happens to equal the host (or host:port) of the request URI is silently removed from the generated curl and http commands. For example, on a request to http://localhost/foo, a header X-Forwarded-Host: localhost disappears from the documented commands. A header with an empty value list is also dropped.

Reproduced on main (3ec9c63, 4.0.2-SNAPSHOT) with a CurlRequestSnippetTests case:

expected: "$ curl 'http://localhost/foo' -i -X GET -H 'X-Forwarded-Host: localhost'"
 but was: "$ curl 'http://localhost/foo' -i -X GET"

Expected: only the Host header is subject to the implicit-host elision; all other headers appear in the snippet regardless of their value. I will submit a PR with a fix and test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions