commonMain.com.apollographql.apollo3.api.http.internal.UrlEncode.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-api-jvm Show documentation
Show all versions of apollo-api-jvm Show documentation
Apollo GraphQL API classes
package com.apollographql.apollo3.api.http.internal
import kotlin.native.concurrent.SharedImmutable
@SharedImmutable
private val RESERVED_CHARS = "!#\$&'\"()*+,/:;=?@[]{}% "
/**
* A very simple urlEncode.
* Note that spaces are encoded as `%20` and not `+`. See:
* - https://stackoverflow.com/a/47188851/15695
* - https://www.rfc-editor.org/rfc/rfc3986#section-2.1
* - https://github.com/apollographql/apollo-kotlin/pull/4567
*/
internal fun String.urlEncode(): String = buildString {
[email protected] { char ->
when (char) {
in RESERVED_CHARS -> append(char.percentEncode())
else -> append(char)
}
}
}
private fun Char.percentEncode(): String {
return "%${code.toString(16)}".uppercase()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy