From 64d39c73119acdf8340d8f1b65966275279e5f83 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Mon, 21 Jun 2021 10:14:21 +0000 Subject: Supports to add a response for the given headers Currently TestHttpServer only supports to add a response for Location header. Make it to add a response for the given headers so that any additional headers that should be returned along with the response. Bug: 181745786 Test: build Original-Change: https://android-review.googlesource.com/1724310 Merged-In: I80b2fe43016b9cd12fc3cb95ee76f1ec9568ddfc Change-Id: I80b2fe43016b9cd12fc3cb95ee76f1ec9568ddfc --- .../devicetests/com/android/testutils/TestHttpServer.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/testutils/devicetests/com/android/testutils/TestHttpServer.kt b/common/testutils/devicetests/com/android/testutils/TestHttpServer.kt index 7aae8e3b..39ce4872 100644 --- a/common/testutils/devicetests/com/android/testutils/TestHttpServer.kt +++ b/common/testutils/devicetests/com/android/testutils/TestHttpServer.kt @@ -54,12 +54,12 @@ class TestHttpServer(host: String? = null) : NanoHTTPD(host, 0 /* auto-select th fun addResponse( uri: Uri, statusCode: Response.IStatus, - locationHeader: String? = null, + headers: Map? = null, content: String = "" ) { addResponse(Request(uri.path ?: "", Method.GET, uri.query ?: ""), - statusCode, locationHeader, content) + statusCode, headers, content) } /** @@ -68,11 +68,13 @@ class TestHttpServer(host: String? = null) : NanoHTTPD(host, 0 /* auto-select th fun addResponse( request: Request, statusCode: Response.IStatus, - locationHeader: String? = null, + headers: Map? = null, content: String = "" ) { val response = newFixedLengthResponse(statusCode, "text/plain", content) - locationHeader?.let { response.addHeader("Location", it) } + headers?.forEach { + (key, value) -> response.addHeader(key, value) + } responses[request] = response } -- cgit v1.2.3