mirror of
https://github.com/apple/pkl.git
synced 2026-06-12 08:34:27 +02:00
Follow HTTP redirects (#328)
- Change HttpClient to follow all redirects except HTTPS to HTTP. - Run language snippet tests with --no-cache and real PackageServer instead of pre-seeded cache. This increases HTTP test coverage and enables testing of package redirects. - Change PackageServer to return 301 for request paths starting with /HTTP301/ and 307 for request paths starting with /HTTP307/. - Update some outdated test package checksums that apparently weren't verified.
This commit is contained in:
@@ -51,6 +51,10 @@ abstract class InputOutputTestEngine :
|
||||
|
||||
protected abstract fun generateOutputFor(inputFile: Path): Pair<Boolean, String>
|
||||
|
||||
protected open fun beforeAll() {}
|
||||
|
||||
protected open fun afterAll() {}
|
||||
|
||||
class ExecutionContext : EngineExecutionContext
|
||||
|
||||
override fun getId(): String = this::class.java.simpleName
|
||||
@@ -78,7 +82,17 @@ abstract class InputOutputTestEngine :
|
||||
(classSelectors.isEmpty() || classSelectors.any { it.className == className })
|
||||
) {
|
||||
|
||||
val rootNode = InputDirNode(uniqueId, inputDir, ClassSource.from(testClass.java))
|
||||
val rootNode =
|
||||
object : InputDirNode(uniqueId, inputDir, ClassSource.from(testClass.java)) {
|
||||
override fun before(context: ExecutionContext): ExecutionContext {
|
||||
beforeAll()
|
||||
return context
|
||||
}
|
||||
|
||||
override fun after(context: ExecutionContext) {
|
||||
afterAll()
|
||||
}
|
||||
}
|
||||
return doDiscover(rootNode, uniqueIdSelectors)
|
||||
}
|
||||
|
||||
@@ -124,7 +138,11 @@ abstract class InputOutputTestEngine :
|
||||
|
||||
override fun createExecutionContext(request: ExecutionRequest) = ExecutionContext()
|
||||
|
||||
private inner class InputDirNode(uniqueId: UniqueId, val inputDir: Path, source: TestSource) :
|
||||
private open inner class InputDirNode(
|
||||
uniqueId: UniqueId,
|
||||
val inputDir: Path,
|
||||
source: TestSource
|
||||
) :
|
||||
AbstractTestDescriptor(uniqueId, inputDir.fileName.toString(), source), Node<ExecutionContext> {
|
||||
override fun getType() = Type.CONTAINER
|
||||
}
|
||||
|
||||
@@ -130,11 +130,23 @@ class PackageServer : AutoCloseable {
|
||||
return@HttpHandler
|
||||
}
|
||||
val path = exchange.requestURI.path
|
||||
if (path.startsWith("/HTTP301/")) {
|
||||
exchange.responseHeaders.add("Location", path.removePrefix("/HTTP301"))
|
||||
exchange.sendResponseHeaders(301, -1)
|
||||
exchange.close()
|
||||
return@HttpHandler
|
||||
}
|
||||
if (path.startsWith("/HTTP307/")) {
|
||||
exchange.responseHeaders.add("Location", path.removePrefix("/HTTP307"))
|
||||
exchange.sendResponseHeaders(307, -1)
|
||||
exchange.close()
|
||||
return@HttpHandler
|
||||
}
|
||||
val localPath =
|
||||
if (path.endsWith(".zip")) packagesDir.resolve(path.drop(1))
|
||||
else packagesDir.resolve("${path.drop(1)}${path}.json")
|
||||
if (!Files.exists(localPath)) {
|
||||
exchange.sendResponseHeaders(404, 0)
|
||||
exchange.sendResponseHeaders(404, -1)
|
||||
exchange.close()
|
||||
return@HttpHandler
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user