Skip to content

Commit

Permalink
Add http scheme if no scheme is provided when creating a HttpRequest … (
Browse files Browse the repository at this point in the history
Azure#313)

* Add http scheme if no scheme is provided when creating a HttpRequest in RestProxy

* Remove adding a default protocol when one isn't specified

* Remove unused exception import
  • Loading branch information
Dan Schulte authored Dec 5, 2017
1 parent a69790d commit 56f228e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public int[] expectedStatusCodes() {
public String scheme(Object[] swaggerMethodArguments) {
final String substitutedHost = applySubstitutions(rawHost, hostSubstitutions, swaggerMethodArguments, UrlEscapers.urlPathSegmentEscaper());
final String[] substitutedHostParts = substitutedHost.split("://");
return substitutedHostParts.length < 1 ? "https" : substitutedHostParts[0];
return substitutedHostParts.length < 1 ? null : substitutedHostParts[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ public String scheme() {
* @return This UrlBuilder so that multiple setters can be chained together.
*/
public UrlBuilder withHost(String host) {
if (host != null && host.endsWith("/")) {
host = host.substring(0, host.length() - 1);
if (host != null) {
if (host.endsWith("/")) {
host = host.substring(0, host.length() - 1);
}

if (host.contains("://")) {
final String[] hostParts = host.split("://");
withScheme(hostParts[0]);
host = hostParts[1];
}
}
this.host = host;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ public void withAbsolutePathAndQuery() {
assertEquals("http://www.othersite.com/mypath?thing=stuff&otherthing=otherstuff", builder.toString());
}

@Test
public void withHostWhenHostContainsProtocol() {
final UrlBuilder builder = new UrlBuilder()
.withHost("https://www.bing.com");
assertEquals("https", builder.scheme());
assertEquals("www.bing.com", builder.host());
assertEquals("https://www.bing.com", builder.toString());
}

@Test
public void parseWithNull() {
assertNull(UrlBuilder.parse(null));
Expand Down

0 comments on commit 56f228e

Please sign in to comment.