Skip to content

Conversation

@Kleinjohann
Copy link

Summary of the changes / Why this is an improvement

Path prefixes in server URLs are now propagated to all requests.
E.g. if the server URL 'http://my-server:1234/crate/' is supplied, requests with SQL queries will be sent to 'http://my-server:1234/crate/_sql?types=true'. Currently, the prefix would be ignored, resulting in 'http://my-server:1234/_sql?types=true' for the same server URL input.
I've encountered multiple setups with proxies that handle forwarding based on path prefixes. This change makes the client work in such setups.

One aspect I'm unsure about:

with patch("crate.client.http.urlparse", side_effect=Exception):
Client("")

Seems like you don't want the client to crash if urllib.parse.urlparse throws an exception, so I wrapped my call in a try-except block:
https://github.com/Kleinjohann/crate-python/blob/d5a7902f44f920646dfe0b19884fc0a635879d19/src/crate/client/http.py#L147-L155
This might however just move unavoidable errors to later stages where they will result in less meaningful error messages. The only hint to anyone trying to debug this would be the warning in the log.
I'm probably missing something here, and it's fine for me to keep it as is, I just somehow didn't feel comfortable implementing it like this.

Fixes #743

@amotl amotl requested a review from mfussenegger January 20, 2026 11:46
Copy link
Member

@mfussenegger mfussenegger left a comment

Choose a reason for hiding this comment

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

Could you also add a note to the CHANGES.rst?

Change looks good to me otherwise.

Comment on lines 182 to 183
path = "/{path_prefix}/{path}".format(
path_prefix=self.path_prefix.strip("/"), path=path.strip("/")
Copy link
Member

Choose a reason for hiding this comment

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

Could you move the .strip("/") for the path_prefix to the CTOR to only do that once per Server instantiation instead of once per request?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, sorry for missing that, I moved the .strip("/").

@Kleinjohann
Copy link
Author

Thanks for your review!
I moved the .strip("/") call, added a bullet point to CHANGES.rst, and rebased to resolve the conflict.

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.

Unable to connect in a proxy setup with path prefix

2 participants