Skip to content

Commit

Permalink
Url encode headers
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Oct 12, 2020
1 parent 3a8ab50 commit 59c8b6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.gitlab.kordlib.rest.request

import com.gitlab.kordlib.rest.route.Route
import io.ktor.http.HeadersBuilder
import io.ktor.http.ParametersBuilder
import io.ktor.http.*
import kotlinx.serialization.SerializationStrategy

class RequestBuilder<T>(private val route: Route<T>, keySize: Int = 2) {
Expand All @@ -23,7 +22,7 @@ class RequestBuilder<T>(private val route: Route<T>, keySize: Int = 2) {

fun parameter(key: String, value: Any) = parameters.append(key, value.toString())

fun header(key: String, value: String) = headers.append(key, value)
fun header(key: String, value: String) = headers.append(key, value.encodeURLQueryComponent())

fun file(name: String, input: java.io.InputStream) {
files.add(name to input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.gitlab.kordlib.rest.ratelimit.ExclusionRequestRateLimiter
import com.gitlab.kordlib.rest.request.KtorRequestHandler
import com.gitlab.kordlib.rest.request.RequestHandler
import com.gitlab.kordlib.rest.service.RestClient
import com.gitlab.kordlib.rest.service.createTextChannel
import io.ktor.client.HttpClient
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.*
Expand Down Expand Up @@ -108,7 +109,16 @@ class RestServiceTest {
@Test
@Order(3)
fun `create channel`() = runBlocking {
val channel = rest.guild.createGuildChannel(guildId, GuildCreateChannelRequest("BOT TEST RUN"))
val channel = rest.guild.createTextChannel(guildId) {
name = "BOT TEST RUN"
reason = """
a multiline
reason
to check if encoding is okay
""".trimIndent()
}
channelId = channel.id

rest.channel.getChannel(channel.id)
Expand Down

0 comments on commit 59c8b6e

Please sign in to comment.