Skip to content

Commit

Permalink
Fix #11129.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Aug 7, 2020
1 parent bca9fc7 commit 4beb4a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions s3/src/main/java/ch/cyberduck/core/s3/S3UrlProvider.java
Expand Up @@ -117,18 +117,27 @@ protected DescriptiveUrl toUrl(final Path file, final Scheme scheme) {
url.append("://");
if(file.isRoot()) {
url.append(session.getHost().getHostname());
if(session.getHost().getPort() != scheme.getPort()) {
url.append(":").append(session.getHost().getPort());
}
}
else {
final String hostname = this.getHostnameForContainer(containerService.getContainer(file));
if(hostname.startsWith(containerService.getContainer(file).getName())) {
url.append(hostname);
if(session.getHost().getPort() != scheme.getPort()) {
url.append(":").append(session.getHost().getPort());
}
if(!containerService.isContainer(file)) {
url.append(Path.DELIMITER);
url.append(URIEncoder.encode(containerService.getKey(file)));
}
}
else {
url.append(session.getHost().getHostname());
if(session.getHost().getPort() != scheme.getPort()) {
url.append(":").append(session.getHost().getPort());
}
url.append(URIEncoder.encode(file.getAbsolute()));
}
}
Expand Down
7 changes: 7 additions & 0 deletions s3/src/test/java/ch/cyberduck/core/s3/S3UrlProviderTest.java
Expand Up @@ -61,6 +61,13 @@ public void testHttpUri() {
new S3UrlProvider(session).toUrl(new Path("/test-us-east-1-cyberduck/key", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.http).getUrl());
}

@Test
public void testHttpUriCustomPort() {
final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), 8443));
assertEquals("https://test-us-east-1-cyberduck.s3.amazonaws.com:8443/key",
new S3UrlProvider(session).toUrl(new Path("/test-us-east-1-cyberduck/key", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.http).getUrl());
}

@Test
public void testToSignedUrlAnonymous() {
final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
Expand Down

0 comments on commit 4beb4a5

Please sign in to comment.