Propagate path prefix in server URLs to all requests#771
Merged
mfussenegger merged 3 commits intocrate:mainfrom Feb 3, 2026
Merged
Propagate path prefix in server URLs to all requests#771mfussenegger merged 3 commits intocrate:mainfrom
mfussenegger merged 3 commits intocrate:mainfrom
Conversation
mfussenegger
approved these changes
Jan 26, 2026
Member
mfussenegger
left a comment
There was a problem hiding this comment.
Could you also add a note to the CHANGES.rst?
Change looks good to me otherwise.
src/crate/client/http.py
Outdated
Comment on lines
182
to
183
| path = "/{path_prefix}/{path}".format( | ||
| path_prefix=self.path_prefix.strip("/"), path=path.strip("/") |
Member
There was a problem hiding this comment.
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?
Contributor
Author
There was a problem hiding this comment.
Good point, sorry for missing that, I moved the .strip("/").
0c6eeee to
564ad74
Compare
Contributor
Author
|
Thanks for your review! |
Member
|
Looks good. Thank you again for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
crate-python/tests/client/test_http.py
Lines 238 to 239 in 7ec1b56
Seems like you don't want the client to crash if
urllib.parse.urlparsethrows 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