| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -253,7 +253,11 @@ static MultipartUploadHttpRequestManager createFrom(HttpStorageOptions options) | |||
| 253 | 253 | storage.getRequestFactory(), | |
| 254 | 254 | new XmlObjectParser(new XmlMapper()), | |
| 255 | 255 | options.getMergedHeaderProvider(FixedHeaderProvider.create(stableHeaders.build())), | |
| 256 | - URI.create(options.getHost())); | ||
| 256 | + URI.create(ensureTrailingSlash(options.getHost()))); | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + private static String ensureTrailingSlash(String host) { | ||
| 260 | + return host.endsWith("/") ? host : host + "/"; | ||
| 257 | 261 | } | |
| 258 | 262 | ||
| 259 | 263 | private void addChecksumHeader(@Nullable Crc32cLengthKnown crc32c, HttpHeaders headers) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,10 @@ public void close() throws Exception { | |||
| 93 | 93 | } | |
| 94 | 94 | ||
| 95 | 95 | static FakeHttpServer of(HttpRequestHandler server) { | |
| 96 | + return of(server, true); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + static FakeHttpServer of(HttpRequestHandler server, boolean trailingSlash) { | ||
| 96 | 100 | // based on | |
| 97 | 101 | // https://github.com/netty/netty/blob/59aa6e635b9996cf21cd946e64353270679adc73/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServer.java | |
| 98 | 102 | InetSocketAddress address = new InetSocketAddress("localhost", 0); | |
@@ -124,7 +128,8 @@ protected void initChannel(SocketChannel ch) { | |||
| 124 | 128 | Channel channel = b.bind(address).syncUninterruptibly().channel(); | |
| 125 | 129 | ||
| 126 | 130 | InetSocketAddress socketAddress = (InetSocketAddress) channel.localAddress(); | |
| 127 | - URI endpoint = URI.create("http://localhost:" + socketAddress.getPort() + "/"); | ||
| 131 | + String suffix = trailingSlash ? "/" : ""; | ||
| 132 | + URI endpoint = URI.create("http://localhost:" + socketAddress.getPort() + suffix); | ||
| 128 | 133 | HttpStorageOptions httpStorageOptions = | |
| 129 | 134 | HttpStorageOptions.http() | |
| 130 | 135 | .setHost(endpoint.toString()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1429,6 +1429,40 @@ public void sendListMultipartUploadsRequest_withUserProject() throws Exception { | |||
| 1429 | 1429 | } | |
| 1430 | 1430 | } | |
| 1431 | 1431 | ||
| 1432 | + @Test | ||
| 1433 | + public void hostWithoutTrailingSlash_urlConstructedCorrectly() throws Exception { | ||
| 1434 | + HttpRequestHandler handler = | ||
| 1435 | + req -> { | ||
| 1436 | + assertThat(req.uri()).startsWith("/test-bucket/test-key"); | ||
| 1437 | + CreateMultipartUploadResponse response = | ||
| 1438 | + CreateMultipartUploadResponse.builder() | ||
| 1439 | + .bucket("test-bucket") | ||
| 1440 | + .key("test-key") | ||
| 1441 | + .uploadId("test-upload-id") | ||
| 1442 | + .build(); | ||
| 1443 | + ByteBuf buf = Unpooled.wrappedBuffer(xmlMapper.writeValueAsBytes(response)); | ||
| 1444 | + DefaultFullHttpResponse resp = | ||
| 1445 | + new DefaultFullHttpResponse(req.protocolVersion(), OK, buf); | ||
| 1446 | + resp.headers().set(CONTENT_TYPE, "application/xml; charset=utf-8"); | ||
| 1447 | + return resp; | ||
| 1448 | + }; | ||
| 1449 | + | ||
| 1450 | + try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler, false)) { | ||
| 1451 | + MultipartUploadHttpRequestManager manager = | ||
| 1452 | + MultipartUploadHttpRequestManager.createFrom(fakeHttpServer.getHttpStorageOptions()); | ||
| 1453 | + CreateMultipartUploadRequest request = | ||
| 1454 | + CreateMultipartUploadRequest.builder() | ||
| 1455 | + .bucket("test-bucket") | ||
| 1456 | + .key("test-key") | ||
| 1457 | + .contentType("application/octet-stream") | ||
| 1458 | + .build(); | ||
| 1459 | + | ||
| 1460 | + CreateMultipartUploadResponse response = manager.sendCreateMultipartUploadRequest(request); | ||
| 1461 | + | ||
| 1462 | + assertThat(response.bucket()).isEqualTo("test-bucket"); | ||
| 1463 | + } | ||
| 1464 | + } | ||
| 1465 | + | ||
| 1432 | 1466 | private void forceSetUploads( | |
| 1433 | 1467 | ListMultipartUploadsResponse response, java.util.List<MultipartUpload> uploads) { | |
| 1434 | 1468 | try { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments