Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ static MultipartUploadHttpRequestManager createFrom(HttpStorageOptions options)
storage.getRequestFactory(),
new XmlObjectParser(new XmlMapper()),
options.getMergedHeaderProvider(FixedHeaderProvider.create(stableHeaders.build())),
URI.create(options.getHost()));
URI.create(ensureTrailingSlash(options.getHost())));
}

private static String ensureTrailingSlash(String host) {
return host.endsWith("/") ? host : host + "/";
}

private void addChecksumHeader(@Nullable Crc32cLengthKnown crc32c, HttpHeaders headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void close() throws Exception {
}

static FakeHttpServer of(HttpRequestHandler server) {
return of(server, true);
}

static FakeHttpServer of(HttpRequestHandler server, boolean trailingSlash) {
// based on
// https://github.com/netty/netty/blob/59aa6e635b9996cf21cd946e64353270679adc73/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServer.java
InetSocketAddress address = new InetSocketAddress("localhost", 0);
Expand Down Expand Up @@ -124,7 +128,8 @@ protected void initChannel(SocketChannel ch) {
Channel channel = b.bind(address).syncUninterruptibly().channel();

InetSocketAddress socketAddress = (InetSocketAddress) channel.localAddress();
URI endpoint = URI.create("http://localhost:" + socketAddress.getPort() + "/");
String suffix = trailingSlash ? "/" : "";
URI endpoint = URI.create("http://localhost:" + socketAddress.getPort() + suffix);
HttpStorageOptions httpStorageOptions =
HttpStorageOptions.http()
.setHost(endpoint.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,40 @@ public void sendListMultipartUploadsRequest_withUserProject() throws Exception {
}
}

@Test
public void hostWithoutTrailingSlash_urlConstructedCorrectly() throws Exception {
HttpRequestHandler handler =
req -> {
assertThat(req.uri()).startsWith("/test-bucket/test-key");
CreateMultipartUploadResponse response =
CreateMultipartUploadResponse.builder()
.bucket("test-bucket")
.key("test-key")
.uploadId("test-upload-id")
.build();
ByteBuf buf = Unpooled.wrappedBuffer(xmlMapper.writeValueAsBytes(response));
DefaultFullHttpResponse resp =
new DefaultFullHttpResponse(req.protocolVersion(), OK, buf);
resp.headers().set(CONTENT_TYPE, "application/xml; charset=utf-8");
return resp;
};

try (FakeHttpServer fakeHttpServer = FakeHttpServer.of(handler, false)) {
MultipartUploadHttpRequestManager manager =
MultipartUploadHttpRequestManager.createFrom(fakeHttpServer.getHttpStorageOptions());
CreateMultipartUploadRequest request =
CreateMultipartUploadRequest.builder()
.bucket("test-bucket")
.key("test-key")
.contentType("application/octet-stream")
.build();

CreateMultipartUploadResponse response = manager.sendCreateMultipartUploadRequest(request);

assertThat(response.bucket()).isEqualTo("test-bucket");
}
}

private void forceSetUploads(
ListMultipartUploadsResponse response, java.util.List<MultipartUpload> uploads) {
try {
Expand Down
Loading