Skip to content

Allow Host to override :authority in HTTP2 - #241

Merged
cdeler merged 7 commits into
encode:masterfrom
chripede:master
Nov 27, 2020
Merged

cdeler merged 7 commits into
encode:masterfrom
chripede:master

Conversation

@chripede

Copy link
Copy Markdown
Contributor

@cdeler

cdeler commented Nov 25, 2020 •

Copy link
Copy Markdown
Contributor

Hello @chripede

You changes are discarded by CI. It happens because some of our files are autogenerated, for example httpcore/_sync/http2.py is generated from httpcore/_async/http2.py. You can do it locally using the script named lint (it is in the project repository scripts/lint)

You can make the changes in the async file, and then update the sync using the lint script

Also, there is the second script named script/test, which can help you to run CI locally (just to check if CI is ok locally)

More information you can find on the project website: testing-and-linting

@florimondmanca florimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good! Left a suggestion to add an explanatory comment.

As @cdeler hinted, the workflow in this repo is to A/ edit files in the _async/ directory, then B/ run scripts/lint to generate the sync version. If following this workflow you should be able to get CI back in check. :-)

Comment thread httpcore/_sync/http2.py
- Added comments to explain why we use the Host header in http/2
@chripede

Copy link
Copy Markdown
Contributor Author

For some reason Black formats the async file different than the sync file. Fixing one linting problem introduces another. Any help would be appreciated ;)

@chripede

Copy link
Copy Markdown
Contributor Author

Nevermind the last comment. Fixing by hand worked and Black doesn't return it to a one-liner.

@cdeler cdeler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good for me 🍦

@florimondmanca florimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small tweak (almost a nitpick, I'm aware), but this is looking good! Any chance we could add a unit test?

Comment thread httpcore/_async/http2.py Outdated
Comment thread httpcore/_async/http2.py Outdated
chripede and others added 2 commits November 26, 2020 15:59
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
@chripede

Copy link
Copy Markdown
Contributor Author

I would create a unit test, but I am unable to run the current set of tests

image

@florimondmanca

Copy link
Copy Markdown
Contributor

@chripede That's hum, interesting. It looks like you're showing the stdout output (pytest -s). What does the pytest final output look like — which tests are failing?

@florimondmanca florimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A unit test would be fab but I'm good with merging this as-is too, so, approving.

@cdeler

cdeler commented Nov 27, 2020

Copy link
Copy Markdown
Contributor

@florimondmanca
I'm merging this ticket as it's approved.
I think it's ok to add new tests in an extra PR linked to #240

@cdeler
cdeler merged commit bdcd5bf into encode:master Nov 27, 2020
Comment thread httpcore/_async/http2.py
b":scheme",
b":path",
)
]

@lovelydinosaur lovelydinosaur Nov 27, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer if we didn't change the pseudo-header behaviour as part of this PR.

There's some complexities here that'd need further discussion. Since this change isn't necessary for the rest of the pull request to make sense, let's treat anything here independently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree that it isn't part of this fix, but I changed it because I tried adding ":authority" to the headers and got an exception because of duplicate headers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure thing. If we want to tackle that let's do so separately tho.

For instance, if we are going to strip pseudo headers like this, then we'd probably also want to do the same for HTTP/1.1 codepaths.

It's part of a more general conversation about "which header values should be treated as valid".

Comment thread httpcore/_async/http2.py
authority = b"%s:%d" % (hostname, port)

if port is not None and port != default_port:
authority = b"%s:%d" % (authority, port)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This case shouldn't override an explicit Host header, so I think there's a bit of tweaking needed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't. At this point, authority has the value of an explicit Host header.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, tho we don't want to append the port here.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants