Skip to content

Add sync httpx node#262

Merged
margaretjgu merged 2 commits intoelastic:mainfrom
sgraaf:add-sync-httpx-node
Feb 25, 2026
Merged

Add sync httpx node#262
margaretjgu merged 2 commits intoelastic:mainfrom
sgraaf:add-sync-httpx-node

Conversation

@sgraaf
Copy link
Copy Markdown
Contributor

@sgraaf sgraaf commented Sep 17, 2025

This PR adds a synchronous node class that uses ahttpx' Client. This would enable developers of downstream packages and applications to use either / both sync and async node classes using only httpx, instead of multiple Python HTTP packages.

The implementation is almost an exact copy of HttpxAsyncHttpNode, stripped of all async / await / a*().

@cla-checker-service
Copy link
Copy Markdown

cla-checker-service Bot commented Sep 17, 2025

💚 CLA has been signed

@sgraaf
Copy link
Copy Markdown
Contributor Author

sgraaf commented Sep 17, 2025

I have now signed the CA!

Copy link
Copy Markdown
Member

@margaretjgu margaretjgu left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together @sgraaf ! This is a great addition!
Just noticed a few small things that should be easy to fix :)

On test coverage, it'd be great to also add HttpxHttpNode to the parametrized lists in test_logging.py and test_httpbin.py (the sync @pytest.mark.parametrize("node_class", ["urllib3", "requests"]) tests) and the test_unknown_parameter case in test_base.py. That way it gets the same integration coverage as the other sync nodes.

Thanks again for the contribution!

Comment thread elastic_transport/_node/_http_httpx.py Outdated
ssl_context.load_cert_chain(config.client_cert)

self.client = httpx.Client(
base_url=f"{config.scheme}://{config.host}:{config.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.

The async node includes config.path_prefix in the base url:

base_url=f"{config.scheme}://{config.host}:{config.port}{config.path_prefix}",

This means path_prefix won't work on the sync node. There's also no test_path_prefix for the sync node (there is one for async in TestHttpxAsyncNodeCreation), so this bug goes undetected by the test suite.

Comment thread elastic_transport/_node/_http_httpx.py Outdated
body=body,
exception=err,
)
raise err from None
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.

Should be similar to async implementation raise err from e for easier debugging. We should match that within sync

Comment thread elastic_transport/_node/_http_httpx.py Outdated

meta = ApiResponseMeta(
resp.status_code,
resp.http_version,
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.

The async node strips the HTTP prefix:

resp.http_version.lstrip("HTTP/"),

Similar to the above, maybe nitpick but I think we should avoid divergence in behaviour between sync/async

@sgraaf sgraaf force-pushed the add-sync-httpx-node branch from 9171fff to 797cc15 Compare February 20, 2026 19:11
@sgraaf
Copy link
Copy Markdown
Contributor Author

sgraaf commented Feb 20, 2026

Thank you for the review & feedback! I've just updated the PR based on your feedback and all should be well now! :)

Please let me know if there are any remaining issues.

@margaretjgu margaretjgu merged commit 411b4df into elastic:main Feb 25, 2026
10 checks passed
@margaretjgu
Copy link
Copy Markdown
Member

Thanks! ill release this within 9.2.2 sometime this week

@margaretjgu
Copy link
Copy Markdown
Member

@sgraaf just an update we'll have to release this new feature in the near future with the next minor release (i.e. 9.4) thanks

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants