-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize URI paths in RestClient #14423
base: main
Are you sure you want to change the base?
Normalize URI paths in RestClient #14423
Conversation
❌ Gradle check result for 0d562b7: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
❌ Gradle check result for fa00762: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
fullPath = path; | ||
} | ||
|
||
String fullPath = buildUriPath(pathPrefix, path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we just need to return new URI("/").resolve(uriBuilder.build().toASCIIString());
to make sure URI is always resolved properly:
new URI("/").resolve("/_render/template") ==> /_render/template
new URI("/").resolve("_render/template") ==> /_render/template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up tweaking the URIBuilder
construction to use its appending rather than building up the full path manually which then takes care of prefixing the /
.
❌ Gradle check result for c2349ff: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
fullPath = path; | ||
URIBuilder uriBuilder = new URIBuilder(); | ||
|
||
if (pathPrefix != null && !pathPrefix.isEmpty() && !"/".equals(pathPrefix)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure the equality checks are suitable here, fe passing //
as path would be a miss, the previous code definitely was more robust towards such cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I was skipping a single /
due to the logic of URIBuilder.appendPath
:
new URIBuilder().appendPath("/").appendPath("/") -> //
new URIBuilder().appendPath("/foo").appendPath("/bar") -> /foo/bar
I've combined this URIBuilder.appendPath
approach with the previous trimSlashes
implementation and some extra test cases to see how we feel about this level of normalization. Though this will strip duplicate /
in leading or trailing position, it won't touch foo////bar
. If we would want to normalize that, then this could be changed to instead split on /
and skip empty segments.
c2349ff
to
0d33093
Compare
❌ Gradle check result for 0d33093: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
0d33093
to
2b8571b
Compare
❌ Gradle check result for 2b8571b: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
2b8571b
to
a59b21e
Compare
❌ Gradle check result for a59b21e: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
There's two tests failing with these changes:
Would be great to hear your thoughts on these two cases @reta? |
Thanks @Xtansia I think for |
This PR is stalled because it has been open for 30 days with no activity. |
@Xtansia Want to finish this? |
This PR is stalled because it has been open for 30 days with no activity. |
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
a59b21e
to
8a6f900
Compare
❌ Gradle check result for 8a6f900: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Description
There are a sprinkling of locations such as this line that construct a RestClient request with a non-absolute path (ie. no leading
/
). This is being passed verbatim to the HTTP request which results in a technically invalid request start-line ofGET _render/template HTTP/1.1
which should beGET /_render/template HTTP/1.1
. OpenSearch itself is lenient and happily serves this request, however in cases of stricter intermediaries such as proxies or load-balances as in Amazon OpenSearch Service, this request ends up denied with a400 Bad Request
.Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.