Skip to content

Conversation

bullet-tooth
Copy link
Contributor

@bullet-tooth bullet-tooth commented Jul 10, 2019

Overview


See: https://jira.bf.local/browse/ECR-3223

  • now the port is optional in the host URL
  • a prefix can be set to all requests

Definition of Done

  • There are no TODOs left in the code
  • Change is covered by automated tests
  • The coding guidelines are followed
  • Public API has Javadoc
  • Method preconditions are checked and documented in the Javadoc of the method
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

@coveralls
Copy link

coveralls commented Jul 10, 2019

Coverage Status

Coverage increased (+0.01%) to 85.672% when pulling 363ee6b on ecr-3223 into 705a1ab on master.

package com.exonum.client;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
Copy link
Contributor

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.
Copy link
Contributor

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) {
Copy link
Contributor

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",
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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 ?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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();
Copy link
Contributor

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?

@dmitry-timofeev
Copy link
Contributor

Would you please also add a short changelog entry?

The build currently fails due unused imports.

bullet-tooth and others added 4 commits July 11, 2019 20:13
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));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷‍♀️

Copy link
Contributor

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));
Copy link
Contributor

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.

@dmitry-timofeev dmitry-timofeev merged commit e378dfa into master Jul 12, 2019
@dmitry-timofeev dmitry-timofeev deleted the ecr-3223 branch July 12, 2019 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants