Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve HTTP header case but compare them case insensitive #1166

Conversation

wendigo
Copy link
Collaborator

@wendigo wendigo commented May 17, 2024

altered copy of #1165

@wendigo wendigo requested a review from findepi May 17, 2024 13:23
@wendigo
Copy link
Collaborator Author

wendigo commented May 17, 2024

cc @losipiuk

@wendigo wendigo force-pushed the findepi/fix-http-request-builder-setheader-case-sensitivity-be0601 branch from 8d856f5 to bd5f3d5 Compare May 17, 2024 14:29
@wendigo wendigo requested a review from electrum May 17, 2024 19:41
Request request = prepareGet()
.setUri(URI.create("http://example.com"))
.addHeader("my-header", "lower")
.addHeader("My-Header", "camel")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@losipiuk suggested better test cases for #1165, so please update

@wendigo wendigo force-pushed the findepi/fix-http-request-builder-setheader-case-sensitivity-be0601 branch from bd5f3d5 to 871266b Compare May 17, 2024 20:40
import static java.util.Objects.requireNonNull;

public final class Request
{
private final URI uri;
private final String method;
private final ListMultimap<String, String> headers;
private final ListMultimap<String, String> headers = createHeadersMultimap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this field immutable.

the Request is built with builder, so the "case-insensitively duplicated" keys are already collapsed to one.
there is however a semantics difference in the getHeader(String) behavior. this should be test covered

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reconsideration I think that we can actually lower-case headers everywhere in the airlift. According to the RFC 7540, Hypertext Transfer Protocol Version 2 (HTTP/2), Section 8.1.2:

Just as in HTTP/1.x, header field names are strings of ASCII characters that are compared in a case-insensitive fashion. However, header field names MUST be converted to lowercase prior to their encoding in HTTP/2. A request or response containing uppercase header field names MUST be treated as malformed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. Nothing that I didn't know. The desire to preserve case is not resulted of a whim, or lack of understanding how http works. i have no hard data to support that desire, it's more like an intuitions that something else can break.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findepi so let's fix the broken places instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wendigo wendigo closed this May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants