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
Change-Id: I80b2fe43016b9cd12fc3cb95ee76f1ec9568ddfc
diff --git a/staticlibs/testutils/devicetests/com/android/testutils/TestHttpServer.kt b/staticlibs/testutils/devicetests/com/android/testutils/TestHttpServer.kt
index 7aae8e3..39ce487 100644
--- a/staticlibs/testutils/devicetests/com/android/testutils/TestHttpServer.kt
+++ b/staticlibs/testutils/devicetests/com/android/testutils/TestHttpServer.kt
@@ -54,12 +54,12 @@
fun addResponse(
uri: Uri,
statusCode: Response.IStatus,
- locationHeader: String? = null,
+ headers: Map<String, String>? = null,
content: String = ""
) {
addResponse(Request(uri.path
?: "", Method.GET, uri.query ?: ""),
- statusCode, locationHeader, content)
+ statusCode, headers, content)
}
/**
@@ -68,11 +68,13 @@
fun addResponse(
request: Request,
statusCode: Response.IStatus,
- locationHeader: String? = null,
+ headers: Map<String, String>? = 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
}