Skip to content

Add HTTP/2 support and protocol version logging#232

Open
jguz-pubnub wants to merge 5 commits into
masterfrom
python-http2
Open

Add HTTP/2 support and protocol version logging#232
jguz-pubnub wants to merge 5 commits into
masterfrom
python-http2

Conversation

@jguz-pubnub
Copy link
Copy Markdown
Contributor

@jguz-pubnub jguz-pubnub commented May 14, 2026

feat: enable HTTP/2 negotiation on the synchronous httpx handler

feat: add http_version field to ResponseInfo

feat: log negotiated protocol version at DEBUG level across all request handlers

- feat: enable HTTP/2 negotiation on the synchronous httpx handler
- feat: add http_version field to ResponseInfo
- feat: log negotiated protocol version at DEBUG level across all request handlers
@jguz-pubnub jguz-pubnub requested a review from parfeon as a code owner May 14, 2026 10:29
@pubnub-ops-terraform
Copy link
Copy Markdown

pubnub-ops-terraform commented May 14, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Comment on lines +177 to +180
logger.debug(
"PubNub request completed: operation=%s protocol=%s"
% (options.operation_type, response_info.http_version)
)
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.

debug probably over informative, but we don't have other levels yet.
I would suggest to merge it with data log above.

Comment thread pubnub/request_handlers/async_httpx.py Outdated
Comment on lines +229 to +232
logger.debug(
"PubNub request completed: operation=%s protocol=%s"
% (options.operation_type, response_info.http_version)
)
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.

debug probably over informative, but we don't have other levels yet.
I would suggest to merge it with data log above.

Comment thread pubnub/request_handlers/requests.py Outdated
Comment on lines +281 to +284
logger.debug(
"PubNub request completed: operation=%s protocol=%s"
% (e_options.operation_type, http_ver)
)
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.

Should we actually print it if version information available in response?

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.

Here's what I've been told to deliver:

Deliverables:

Debug logs such as:

PubNub request completed: operation=subscribe protocol=HTTP/2
PubNub request completed: operation=publish protocol=HTTP/1.1

I'll try to make it less noisy and merge it with data logs you suggested

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.

Ok, I've missed operation in the format.

Comment thread requirements-dev.txt
pytest-asyncio>=1.0.0
httpx>=0.28
h2>=4.1
h2>=4.3
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.

This is only development dependencies, but there is actual package dependencies which needs to be updated as well in setup.py.

Comment thread pubnub/request_handlers/httpx.py Outdated
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.

This one should be instructed in a same way as AsyncClient need to specify http2=True in constructor.

Comment thread pubnub/request_handlers/async_httpx.py Outdated
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.

But where is http2=True in constructor?

client_request=None,
client_response=response
client_response=response,
http_version=f"HTTP/{response.version.major}.{response.version.minor}" if response.version else None
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.

Interesting, that aiohttp dopes't support HTTP/2 at all.

Copy link
Copy Markdown
Contributor Author

@jguz-pubnub jguz-pubnub May 27, 2026

Choose a reason for hiding this comment

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

Indeed, but there's nothing we can do here, and we need to ensure that our API is transport-resilient. I would keep setting a http_version field for consistency, even though it will always be HTTP/1.1. What's your take on that?

auth_key=auth_key,
client_request=res.request
client_request=res.request,
http_version=(
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.

Same as aiohttp this one native request based on urllib3 also doesn't support HTTP/2 - they fundraising for it on their webpage.

Copy link
Copy Markdown
Contributor Author

@jguz-pubnub jguz-pubnub May 27, 2026

Choose a reason for hiding this comment

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

Indeed, but there's nothing we can do here, and we need to ensure that our API is transport-resilient. I would keep setting a http_version field for consistency, even though it will always be HTTP/1.1. What's your take on that?

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.

3 participants