awslabs / aws-sdk-kotlin

Multiplatform AWS SDK for Kotlin
Apache License 2.0
411 stars 49 forks source link

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

Closed tylerjroach closed 10 months ago

tylerjroach commented 11 months ago

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: https://github.com/aws-amplify/amplify-android/issues/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

ianbotsf commented 10 months ago

Resolved by https://github.com/awslabs/smithy-kotlin/pull/1019

github-actions[bot] commented 10 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.