Skip to content

S3 PUT http with url-connection-client contentEncoding is always "aws-chunked" #4746

@youngm

Description

@youngm

Describe the bug

When putting an S3Object connecting to S3 via http and url-connection-client, the contentEncoding for that object is always "aws-chunked".

Expected Behavior

The contentEncoding should be whatever is set in the PutObjectRequest.

Current Behavior

contentEncoding is always aws-chunked when connecting to s3 via http and url-connection-client.

Reproduction Steps

This test creates an object using http s3 and sets a contentEncoding. Note that the contentEncoding is changed to "aws-chunked" by the sdk.

S3Test.java

public class S3Test {

  @Test
  public void test() throws Exception {
    try (var s3Client =
        S3Client.builder()
            .endpointOverride(URI.create("http://s3.amazonaws.com"))
            .build()) {
    var putRequest =
        PutObjectRequest.builder()
            .bucket("bucket")
            .key("file")
            .contentEncoding("bogus")
            .build();

    s3Client.putObject(putRequest, RequestBody.empty());
    try (var response =
        s3Client.getObject(GetObjectRequest.builder().bucket("bucket").key("file").build())) {
    assertThat(response.response().contentEncoding()).isEqualTo("bogus");
    }
    }
  }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.1.5</version>
	</parent>
	<modelVersion>4.0.0</modelVersion>
	<groupId>s3test</groupId>
	<artifactId>s3test</artifactId>
	<version>1.0</version>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>software.amazon.awssdk</groupId>
				<artifactId>bom</artifactId>
				<version>2.21.36</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>software.amazon.awssdk</groupId>
			<artifactId>s3</artifactId>
			<exclusions>
				<exclusion>
					<groupId>software.amazon.awssdk</groupId>
					<artifactId>netty-nio-client</artifactId>
				</exclusion>
				<exclusion>
					<groupId>software.amazon.awssdk</groupId>
					<artifactId>apache-client</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>software.amazon.awssdk</groupId>
			<artifactId>url-connection-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.assertj</groupId>
			<artifactId>assertj-core</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>

Possible Solution

PutObjectRequest should behave the same no matter the client used or http vs https. I don't know what exactly is causing the wrong contentEncoding to be sent in this situation.

Additional Information/Context

This is a re-opening of #4725.

AWS Java SDK version used

2.21.16+

JDK version used

17

Operating System and version

Windows 11

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions