mirror of
https://github.com/square/okhttp.git
synced 2026-01-17 08:42:25 +03:00
Merge pull request #1789 from MichaelEvans/changing_scheme_fixes_default_ports
Changing the scheme will update the default port
This commit is contained in:
@@ -602,6 +602,23 @@ public final class HttpUrlTest {
|
||||
assertEquals("fragment", url.fragment());
|
||||
}
|
||||
|
||||
@Test public void changingSchemeChangesDefaultPort() throws Exception {
|
||||
assertEquals(443, HttpUrl.parse("http://example.com")
|
||||
.newBuilder()
|
||||
.scheme("https")
|
||||
.build().port());
|
||||
|
||||
assertEquals(80, HttpUrl.parse("https://example.com")
|
||||
.newBuilder()
|
||||
.scheme("http")
|
||||
.build().port());
|
||||
|
||||
assertEquals(1234, HttpUrl.parse("https://example.com:1234")
|
||||
.newBuilder()
|
||||
.scheme("http")
|
||||
.build().port());
|
||||
}
|
||||
|
||||
@Test public void composeEncodesWhitespace() throws Exception {
|
||||
HttpUrl url = new HttpUrl.Builder()
|
||||
.scheme("http")
|
||||
|
||||
@@ -570,7 +570,12 @@ public final class HttpUrl {
|
||||
result.encodedUsername = encodedUsername();
|
||||
result.encodedPassword = encodedPassword();
|
||||
result.host = host;
|
||||
result.port = port;
|
||||
// If we're set to a default port, unset it, in case of a scheme change.
|
||||
if (port == defaultPort(scheme)) {
|
||||
result.port = -1;
|
||||
} else {
|
||||
result.port = port;
|
||||
}
|
||||
result.encodedPathSegments.clear();
|
||||
result.encodedPathSegments.addAll(encodedPathSegments());
|
||||
result.encodedQuery(encodedQuery());
|
||||
|
||||
Reference in New Issue
Block a user