Skip to content

Commit

Permalink
Do not setup content encoding for js and native
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Jul 10, 2023
1 parent f612f3b commit 32c71a7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
set -eux
./gradlew compileTestKotlinJvm $GRADLE_ARGS
- name: Compile JS
- name: Compile native
run: |
set -eux
./gradlew compileTestKotlinJs $GRADLE_ARGS
./gradlew linkDebugTestNative $GRADLE_ARGS
- name: Compile native
- name: Compile JS
run: |
set -eux
./gradlew linkDebugTestNative $GRADLE_ARGS
./gradlew compileTestKotlinJs $GRADLE_ARGS
- name: Compile samples
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import io.ktor.http.contentType
import io.ktor.http.path
import io.ktor.http.takeFrom

internal expect val setupContentEncoding: ContentEncoding.Config.() -> Unit

class ElasticsearchKtorTransport(
baseUrl: String,
engine: HttpClientEngine,
Expand All @@ -30,11 +32,7 @@ class ElasticsearchKtorTransport(
expectSuccess = false

// Enable compressed response from Elasticsearch
install(ContentEncoding) {
gzip()
deflate()
identity()
}
install(ContentEncoding, setupContentEncoding)

when (val auth = config.auth) {
is dev.evo.elasticmagic.transport.Auth.Basic -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.evo.elasticmagic.transport

import dev.evo.elasticmagic.serde.platform
import dev.evo.elasticmagic.serde.Platform
import dev.evo.elasticmagic.serde.toMap
import dev.evo.elasticmagic.serde.kotlinx.JsonDeserializer
import dev.evo.elasticmagic.serde.kotlinx.JsonSerde
import dev.evo.elasticmagic.serde.kotlinx.JsonSerializer
import dev.evo.elasticmagic.serde.toMap

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.comparables.shouldBeGreaterThan
Expand Down Expand Up @@ -38,13 +40,19 @@ import kotlin.time.Duration

@ExperimentalStdlibApi
class ElasticsearchKtorTransportTests {
private val expectedAcceptEncoding = if (platform == Platform.JVM) {
"gzip,deflate,identity"
} else {
""
}

@Test
fun headRequest() = runTest {
val client = ElasticsearchKtorTransport(
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Head
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/products"
request.body.contentType.shouldBeNull()
request.body.toByteArray().decodeToString().shouldBeEmpty()
Expand Down Expand Up @@ -74,7 +82,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Put
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/products/_settings"
request.body.contentType shouldBe ContentType.Application.Json
request.body.toByteArray().decodeToString() shouldBe """{"index":{"number_of_replicas":2}}"""
Expand Down Expand Up @@ -113,7 +121,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Delete
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/products_v2"
request.body.toByteArray().decodeToString().shouldBeEmpty()

Expand Down Expand Up @@ -144,7 +152,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Post
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/_bulk"
request.body.contentType shouldBe ContentType("application", "x-ndjson")
val rawBody = request.body.toByteArray().decodeToString()
Expand Down Expand Up @@ -210,7 +218,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Get
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/_cat/nodes"
request.body.contentType.shouldBeNull()
respond(
Expand Down Expand Up @@ -238,7 +246,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Post
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/products_v2/_forcemerge"
request.body.toByteArray().decodeToString().shouldBeEmpty()
respondError(
Expand Down Expand Up @@ -266,7 +274,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Get
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/products/_count"
request.body.contentType.shouldBeNull()
request.body.toByteArray().decodeToString().shouldBeEmpty()
Expand Down Expand Up @@ -322,7 +330,7 @@ class ElasticsearchKtorTransportTests {
"http://example.com:9200",
MockEngine { request ->
request.method shouldBe HttpMethod.Get
request.headers["accept-encoding"] shouldBe "gzip,deflate,identity"
request.headers["accept-encoding"] shouldBe expectedAcceptEncoding
request.url.encodedPath shouldBe "/products/_search"
request.body.contentType shouldBe ContentType.Application.Json
request.body.toByteArray().decodeToString() shouldBe expectedContent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.evo.elasticmagic.transport

import io.ktor.client.plugins.compression.ContentEncoding

internal actual val setupContentEncoding: ContentEncoding.Config.() -> Unit = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.evo.elasticmagic.transport

import io.ktor.client.plugins.compression.ContentEncoding

internal actual val setupContentEncoding: ContentEncoding.Config.() -> Unit = {
gzip()
deflate()
identity()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.evo.elasticmagic.transport

import io.ktor.client.plugins.compression.ContentEncoding

internal actual val setupContentEncoding: ContentEncoding.Config.() -> Unit = {}

0 comments on commit 32c71a7

Please sign in to comment.