Skip to content

Comments

Add sync httpx node#262

Open
sgraaf wants to merge 2 commits intoelastic:mainfrom
sgraaf:add-sync-httpx-node
Open

Add sync httpx node#262
sgraaf wants to merge 2 commits intoelastic:mainfrom
sgraaf:add-sync-httpx-node

Conversation

@sgraaf
Copy link

@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

cla-checker-service bot commented Sep 17, 2025

💚 CLA has been signed

@sgraaf
Copy link
Author

sgraaf commented Sep 17, 2025

I have now signed the CA!

Copy link
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!

ssl_context.load_cert_chain(config.client_cert)

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

body=body,
exception=err,
)
raise err from None
Copy link
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


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

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