Skip to content

Commit 3e4d12f

Browse files
committed
Add redirection for descriptors downloads
1 parent e25b0a4 commit 3e4d12f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

kotlin-jupyter-plugin/common-dependencies/src/main/kotlin/org/jetbrains/kotlinx/jupyter/common/httpUtil.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import kotlinx.serialization.json.JsonElement
88
import kotlinx.serialization.json.JsonObject
99
import org.http4k.asString
1010
import org.http4k.client.ApacheClient
11+
import org.http4k.core.HttpHandler
1112
import org.http4k.core.Method
1213
import org.http4k.core.Request
1314
import org.http4k.core.Response
15+
import org.http4k.core.then
16+
import org.http4k.filter.ClientFilters
1417
import java.io.IOException
1518
import java.util.Base64
1619

@@ -19,8 +22,12 @@ class ResponseWrapper(
1922
val url: String,
2023
) : Response by response
2124

25+
fun createHttpClient(): HttpHandler {
26+
return ClientFilters.FollowRedirects().then(ApacheClient())
27+
}
28+
2229
fun httpRequest(request: Request): ResponseWrapper {
23-
val client = ApacheClient()
30+
val client = createHttpClient()
2431
val response = client(request)
2532

2633
return ResponseWrapper(response, request.uri.toString())

src/test/kotlin/org/jetbrains/kotlinx/jupyter/test/repl/ReplWithStandardResolverTests.kt

+11
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ class ReplWithStandardResolverTests : AbstractSingleReplTest() {
102102
assertEquals(44, res4.resultValue)
103103
}
104104

105+
@Test
106+
fun testHttpRedirection() {
107+
val res = eval(
108+
"""
109+
%use jep@url[https://github.com/hanslovsky/jepyter/releases/download/jepyter-0.1.8/jep.json]
110+
1
111+
""".trimIndent()
112+
).resultValue
113+
assertEquals(1, res)
114+
}
115+
105116
@Test
106117
fun testLocalLibrariesStorage() {
107118
@Language("json")

0 commit comments

Comments
 (0)