commonMain.aws.smithy.kotlin.runtime.http.util.Text.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-jvm Show documentation
Show all versions of http-jvm Show documentation
HTTP core for Smithy clients and services generated by smithy-kotlin
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.smithy.kotlin.runtime.http.util
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.util.text.VALID_PCHAR_DELIMS
import aws.smithy.kotlin.runtime.util.text.encodeUrlPath
// RFC-3986 §3.3 allows sub-delims (defined in section2.2) to be in the path component.
// This includes both colon ':' and comma ',' characters.
// Smithy protocol tests & AWS services percent encode these expected values. Signing
// will fail if these values are not percent encoded
private val VALID_HTTP_LABEL_DELIMS: Set = VALID_PCHAR_DELIMS - "/ :,?#[]()@!$&'*+;=%".toSet()
private val GREEDY_HTTP_LABEL_DELIMS: Set = VALID_HTTP_LABEL_DELIMS + '/'
/**
* Encode a value that represents a member bound via `httpLabel`
* See: https://awslabs.github.io/smithy/1.0/spec/core/http-traits.html#httplabel-trait
*
* @param greedy Flag indicating this label is "greedy" (which allows for the value to have path separators in it)
* See: https://awslabs.github.io/smithy/1.0/spec/core/http-traits.html#greedy-labels
*/
@InternalApi
public fun String.encodeLabel(greedy: Boolean = false): String {
val validDelims = if (greedy) {
GREEDY_HTTP_LABEL_DELIMS
} else {
VALID_HTTP_LABEL_DELIMS
}
return encodeUrlPath(validDelims, checkPercentEncoded = false)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy