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

Fix HTTP version in debug log #3316

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pquentin
Copy link
Member

Addresses #3297 (comment). It isn't great, but it will log HTTP/0 for emscripten, HTTP/20 for HTTP/2 and HTTP/11 for HTTP/1.1. Is it time to add an actual http_version or version_string in BaseHTTPResponse alongside version?

@pquentin pquentin added the Skip Changelog Pull requests that don't require a changelog entry label Jan 25, 2024
This trick was used in the hyper HTTP/2 client, and has two advantages:

 1. it is impossible to use the connection without acquiring the lock
 2. passing the connection to another object only requires one parameter
self.scheme,
self.host,
self.port,
method,
url,
# HTTP version
http_version,
response.version,
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on using *divmod(response.version, 10)?

Copy link
Member Author

@pquentin pquentin Jan 26, 2024

Choose a reason for hiding this comment

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

It would give HTTP/2.0 which is less wrong but still weird? I think I would prefer storing the version string in the response? It can be done without any computation and only costs a few bytes

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I do like HTTP/2 in the logs better too.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this, we should probably keep emitting HTTP/1.1 and HTTP/2 since some folks might be using regular expressions on these values. Can we have an if block that determines the value based on the resp.version value?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a way to avoid ifs, what do you think of a1f18b0?

@@ -482,6 +482,7 @@ def getresponse( # type: ignore[override]
headers=headers,
status=httplib_response.status,
version=httplib_response.version,
version_string=getattr(self, "_http_vsn_str", "HTTP/?"),
Copy link
Member Author

Choose a reason for hiding this comment

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

Emscripten has its own connection class, so I don't need the getattr any more:

Suggested change
version_string=getattr(self, "_http_vsn_str", "HTTP/?"),
version_string=self._http_vsn_str,

Copy link
Member Author

Choose a reason for hiding this comment

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

But I do need to add version_string to

. Hopefully CI will catch this (did not run so far).

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

Approach LGTM, looks like a linting error and Emscripten tests failing.

@sethmlarson sethmlarson closed this May 1, 2024
@sethmlarson sethmlarson reopened this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Pull requests that don't require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants