summaryrefslogtreecommitdiffstats
path: root/vespa-http-client
diff options
context:
space:
mode:
authorHaakon Dybdahl <dybdahl@yahoo-inc.com>2016-09-21 08:33:36 +0200
committerHaakon Dybdahl <dybdahl@yahoo-inc.com>2016-09-21 08:33:36 +0200
commit562d90334373274ba0b9904fcb59c7cbd120d6c3 (patch)
tree636ac2faf1817836d2f5f2517fc84a69f85d8799 /vespa-http-client
parentd72e94e51b667329c7aad73ffef1c2a13ddb2beb (diff)
Allow servername prefixed with http.
Diffstat (limited to 'vespa-http-client')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java10
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/config/EndpointTest.java11
2 files changed, 20 insertions, 1 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java
index b23480f9251..6c2e162f15b 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Endpoint.java
@@ -41,7 +41,15 @@ public final class Endpoint {
private final boolean useSsl;
private static final int DEFAULT_PORT = 4080;
private Endpoint(String hostname, int port, boolean useSsl) {
- this.hostname = hostname;
+ if (hostname.startsWith("https://")) {
+ throw new RuntimeException("Hostname should be name of machine, not prefixed with protocol (https://)");
+ }
+ // A lot of people put http:// before the servername, let us allow that.
+ if (hostname.startsWith("http://")) {
+ this.hostname = hostname.replaceFirst("http://", "");
+ } else {
+ this.hostname = hostname;
+ }
this.port = port;
this.useSsl = useSsl;
}
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/config/EndpointTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/config/EndpointTest.java
index e5718a4ba20..ab59bde5485 100644
--- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/config/EndpointTest.java
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/config/EndpointTest.java
@@ -24,6 +24,17 @@ public class EndpointTest {
}
@Test
+ public void testBasicWithHttpProtocolPrefix() {
+ Endpoint endpoint = Endpoint.create("http://foo");
+ assertThat(endpoint.getHostname(), equalTo("foo"));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testBasicWithHttpsProtocolPrefix() {
+ Endpoint.create("https://foo");
+ }
+
+ @Test
public void testAdvanced() {
Endpoint endpoint = Endpoint.create("bar", 1234, true);