Skip to content

Commit 4559e7f

Browse files
author
Denver
committed
Merge pull request #220 from rpmoore/http_host_fix_3_2_autogen
If the host field has http:// it will be removed when put into the Ho…
2 parents 3344037 + 828c454 commit 4559e7f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,16 @@ private static String bucketPath(final String bucket) {
120120
}
121121

122122
public static String buildHostField(final ConnectionDetails details) {
123-
return details.getEndpoint();
123+
return filterHttp(details.getEndpoint());
124+
}
125+
126+
public static String filterHttp(final String url) {
127+
if (url.startsWith("http://") || url.startsWith("https://"))
128+
{
129+
final int colonIndex = url.indexOf(":");
130+
return url.substring(colonIndex + 3);
131+
}
132+
return url;
124133
}
125134

126135
public static int getPort(final URL url) {

ds3-sdk/src/test/java/com/spectralogic/ds3client/ConnectionFixture.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ public static ConnectionDetails getConnection() {
2727
public static ConnectionDetails getConnection(final int port) {
2828
return ConnectionDetailsImpl.builder("localhost:" + port, new Credentials("id", "key")).build();
2929
}
30+
31+
public static ConnectionDetails getHttpConnection() {
32+
return getHttpConnection(8080);
33+
}
34+
35+
public static ConnectionDetails getHttpConnection(final int port) {
36+
return ConnectionDetailsImpl.builder("http://localhost:" + port, new Credentials("id", "key")).build();
37+
}
3038
}

ds3-sdk/src/test/java/com/spectralogic/ds3client/utils/NetUtils_Test.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ public void getHttpDefaultPort() throws MalformedURLException {
167167
assertTrue(port == 80);
168168
}
169169

170+
@Test
171+
public void buildHostFieldWithHttp() {
172+
final String result = NetUtils.buildHostField(ConnectionFixture.getHttpConnection());
173+
assertThat(result, is("localhost:8080"));
174+
}
175+
170176
@Test
171177
public void buildHost() throws MalformedURLException {
172178
final ConnectionDetails details = new ConnectionDetails() {

0 commit comments

Comments
 (0)