awslabs / aws-sdk-kotlin

Multiplatform AWS SDK for Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PutObjectRequest metadata with non ASCII characters will fail to set OkHttp Headers

tylerjroach opened this issue Β· comments

Describe the bug

If PubObjectRequest (likely all other storage request types) metadata contains non-ASCII characters in a header pair, the request will fail.

OkHttp does not accept non-ASCII characters by default and requires adding flag for leniency or https://square.github.io/okhttp/5.x/okhttp/okhttp3/-headers/-builder/add-unsafe-non-ascii.html.

DefaultS3Client appears to use the default OkHttp config not allowing non-ASCII header values.

See report from Amplify v2 for more info: aws-amplify/amplify-android#2657

Expected behavior

Allow non-ASCII characters in header values.

Current behavior

Request never attempted.

Caused by: java.lang.IllegalArgumentException: Unexpected char 0xd83d at 0 in x-amz-meta-custom value: 😏
	at okhttp3.internal._HeadersCommonKt.headersCheckValue(-HeadersCommon.kt:140)
	at okhttp3.internal._HeadersCommonKt.commonAdd(-HeadersCommon.kt:77)
	at okhttp3.Headers$Builder.add(Headers.kt:166)
	at okhttp3.internal._RequestCommonKt.commonAddHeader(-RequestCommon.kt:60)
	at okhttp3.Request$Builder.addHeader(Request.kt:221)
	at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpUtilsKt$toOkHttpRequest$1.invoke(OkHttpUtils.kt:54)
	at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpUtilsKt$toOkHttpRequest$1.invoke(OkHttpUtils.kt:52)
	at aws.smithy.kotlin.runtime.util.ValuesMap$DefaultImpls.forEach(ValuesMap.kt:54)
	at aws.smithy.kotlin.runtime.util.ValuesMapImpl.forEach(ValuesMap.kt:69)
	at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpUtilsKt.toOkHttpRequest(OkHttpUtils.kt:52)

Steps to Reproduce

Initiate:

PutObjectRequest {
  ...
  metadata = mapOf("custom" to "😏")
  ...
}

execute request

Possible Solution

No response

Context

No response

AWS Kotlin SDK version used

All

Platform (JVM/JS/Native)

JVM

Operating System and version

Android