Skip to content

Commit 04882bb

Browse files
committed
Add redirect following for http client
1 parent 92d6215 commit 04882bb

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

json-schema-validator/src/jvmTest/kotlin/io/github/optimumcode/json/schema/JsonSchemaStreamTest.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.optimumcode.json.schema
22

3+
import io.kotest.assertions.asClue
34
import io.kotest.assertions.throwables.shouldNotThrowAny
45
import io.kotest.core.spec.style.FunSpec
56
import kotlinx.serialization.ExperimentalSerializationApi
@@ -14,17 +15,24 @@ import java.time.Duration
1415
class JsonSchemaStreamTest : FunSpec() {
1516
init {
1617
test("definition is loaded from input stream") {
17-
shouldNotThrowAny {
18-
val client = HttpClient.newHttpClient()
19-
val response =
20-
client.send(
21-
HttpRequest.newBuilder(URI.create("https://json-schema.org/draft-07/schema#"))
22-
.GET()
23-
.timeout(Duration.ofSeconds(10))
24-
.build(),
25-
BodyHandlers.ofInputStream(),
26-
)
27-
response.body().use(JsonSchema::fromStream)
18+
19+
val client =
20+
HttpClient.newBuilder()
21+
.followRedirects(HttpClient.Redirect.NORMAL)
22+
.build()
23+
24+
val response =
25+
client.send(
26+
HttpRequest.newBuilder(URI.create("https://json-schema.org/draft-07/schema#"))
27+
.GET()
28+
.timeout(Duration.ofSeconds(10))
29+
.build(),
30+
BodyHandlers.ofInputStream(),
31+
)
32+
"Response code: ${response.statusCode()}".asClue {
33+
shouldNotThrowAny {
34+
response.body().use(JsonSchema::fromStream)
35+
}
2836
}
2937
}
3038
}

0 commit comments

Comments
 (0)