-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add HttpUrl class #49
Conversation
fyi @ellisjoe |
nvm, will have to tweak this to be correct. |
import java.util.List; | ||
|
||
/** A simplistic URL builder, not tuned for performance. */ | ||
public final class HttpUrl { |
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.
maybe UrlBuilder
?
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.
also might consider just making the top-level class the builder and have the 'build' method be toUrl
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.
done
private String host; | ||
private int port = -1; | ||
private List<String> pathSegments = new ArrayList<>(); | ||
private List<String> queryNamesAndValues = new ArrayList<>(); // alternating (name, value) pairs |
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.
might make more sense for this to be a Multimap
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 suspect the list construction has fewer allocations; I think it's OK since it's just used internally?
|
||
private static String encodePath(List<String> pairs) { | ||
StringBuilder result = new StringBuilder(); | ||
for (int i = 0; i < pairs.size(); i += 1) { |
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.
possibly nicer to write this as:
Joiner.on("/").join(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.
done here, but not below to save object allocations
return URLEncoder.encode(string, StandardCharsets.UTF_8); | ||
} | ||
|
||
private static String encodePath(List<String> pairs) { |
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.
pairs
-> 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.
done
you may want to consider looking at URI, the docs on URL say this:
|
problem with the URI class is that it cannot distinguish between |
take another look please, @markelliot |
dialogue-java-client/src/main/java/com/palantir/dialogue/UrlBuilder.java
Show resolved
Hide resolved
dialogue-java-client/src/main/java/com/palantir/dialogue/UrlBuilder.java
Show resolved
Hide resolved
take another look please, @markelliot |
No description provided.