Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-3566 Fixed sending DELETE with body in Curl engine #3165

Merged
merged 1 commit into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/test/server/ClientTestServer.kt
Expand Up @@ -69,6 +69,9 @@ internal fun Application.tests() {
val contentType = call.request.header(HttpHeaders.ContentType)
call.respondText(contentType ?: "")
}
delete("/delete") {
call.respondText("OK ${call.receiveText()}")
}
}
}

Expand Down
Expand Up @@ -155,15 +155,16 @@ internal class CurlMultiApiHandler : Closeable {
easyHandle.apply {
when (method) {
"GET" -> option(CURLOPT_HTTPGET, 1L)
"PUT" -> {
option(CURLOPT_PUT, 1L)
}
"PUT" -> option(CURLOPT_PUT, 1L)
"POST" -> {
option(CURLOPT_POST, 1L)
option(CURLOPT_POSTFIELDSIZE, size)
}
"HEAD" -> option(CURLOPT_NOBODY, 1L)
else -> option(CURLOPT_CUSTOMREQUEST, method)
else -> {
if (size > 0) option(CURLOPT_POST, 1L)
option(CURLOPT_CUSTOMREQUEST, method)
}
}
}
}
Expand Down
Expand Up @@ -8,31 +8,34 @@ import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.curl.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.*
import kotlin.native.concurrent.*
import kotlin.test.*

val backgroundWorker = Worker.start()

class CurlNativeTests {

private val TEST_SERVER: String = "http://127.0.0.1:8080"

@Test
@Ignore
fun testDownloadInBackground() {
backgroundWorker.execute(TransferMode.SAFE, { Unit }) {
runBlocking {
val client = HttpClient(Curl)
client.get("http://google.com").body<String>()
}
}.consume { assert(it.isNotEmpty()) }
fun testDownload() = runBlocking {
HttpClient(Curl).use {
val res = it.get("http://google.com").body<String>()
assert(res.isNotEmpty())
}
}

@Test
fun testDownload() {
runBlocking {
val client = HttpClient(Curl)
val res = client.get("http://google.com").body<String>()
assert(res.isNotEmpty())
fun testDelete(): Unit = runBlocking {
HttpClient(Curl).use {
val response = it.delete("$TEST_SERVER/delete")
assertEquals("OK ", response.bodyAsText())

val responseWithBody = it.delete("$TEST_SERVER/delete") {
setBody("1")
}
assertEquals("OK 1", responseWithBody.bodyAsText())
}
}
}