-
Notifications
You must be signed in to change notification settings - Fork 30
[ECR-3223] LC: port is optional; added prefix #997
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
Conversation
package com.exonum.client; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static java.util.Objects.requireNonNull; |
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.
Why don't we use the already used locally checkNotNull?
} | ||
|
||
/** | ||
* Optionally, sets prefix url to be applied to all requests made by the client. |
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.
Sets an optional URL prefix [= not optionally sets]...
+ There is no prefix by default.
final class HttpUrlHelper { | ||
|
||
static HttpUrl getFullUrl(URL host, String prefix, String relativeUrl, | ||
Map<String, String> query) { |
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.
(encoded)QueryParams/Parameters?
private static List<Arguments> source() { | ||
Map<String, String> noQuery = emptyMap(); | ||
return ImmutableList.of( | ||
of("http://localhost/path/to/source", |
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.
Lone of
is off 🙃 , please replace with arguments
.
|
||
/** | ||
* Removes heading slash from the path. | ||
* Useful because underlying OkHttp applies slashes when constructing paths. |
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.
Doesn't okhttp do that itself? Also, double slashes must not cause any problems, mustn't they?
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.
No, okhttp doesn't do that :(
Urls with double stashes are valid. But such urls semantically identical but not equal. It may cause issues when storing them in collections and potentially cause some issues on a server side, for example caching (where the cache key is a path to the resource).
I see this question is more complex: such as we allow users to specify host and prefix in a string form may be do we need to have a full normalization urls support, for example as described here ?
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 see, do I understand it correctly that we do the normalization to aid caching on a (possibly, intermediate) server in cases where the user has optional leading and/or trailing slashes? Isn't the naive approach used here enough?
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.
Yes, right.
But, I believe, we can simplify this and remove normalization and rely fully on OkHttp.
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 must admit that the URLs look better normalized, but agree it is not strictly needed (if a user cares, they can omit the slashes) :-)
* - port is optional | ||
* - prefix is optional | ||
* - paths can start either with or without heading slash | ||
* - query params is optional. |
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.
are optional
?
return path; | ||
} | ||
private static HttpUrl normalize(HttpUrl url) { | ||
URI normalized = url.uri().normalize(); |
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 is no longer a naïve approach 🙃 Shall we add more tests specific to this normalization algorithm to exercise that?
Would you please also add a short changelog entry? The build currently fails due unused imports. |
fixed build
# Conflicts: # exonum-light-client/CHANGELOG.md # exonum-light-client/src/main/java/com/exonum/client/ExonumHttpClient.java
} | ||
|
||
static void assertExactPath(RecordedRequest request, String url) { | ||
assertThat(request.getPath(), is("/" + url)); |
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.
🤷♀️
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'd try with matchers, as these are unclear.
} | ||
|
||
static void assertExactPath(RecordedRequest request, String url) { | ||
assertThat(request.getPath(), is("/" + url)); |
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'd try with matchers, as these are unclear.
Overview
See: https://jira.bf.local/browse/ECR-3223
Definition of Done