Modern Apps git

← Modern-Apps.git

share: preserve response headers in AirDropHttp.readResponse

Commit
9acca39ad4a8b8c1f9b7fcb0295a4e954e3e0cf5
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:17 UTC (28 days ago)
Parents
5f3ebc6
readResponse parsed the response headers, used them to pick the body
decoder, then threw them away and returned Response(status,
emptyMap(), body) — even though Response carries a headers field and
the server half (writeResponse) faithfully emits them. Any caller
needing Content-Type, Connection, or a future extension header from a
real device got null.

Return the parsed headers (new Headers.toMap snapshot, keys
lowercased as Headers.get already expects). No caller changes: the
sender only reads status/body today, so this is additive.

Verified with :share:testDevUnitTest (new headers round-trip test in
AirDropHttpTest; full network.airdrop package green).

Diff

share/src/main/java/com/vayunmathur/share/network/airdrop/AirDropHttp.kt
diff --git a/share/src/main/java/com/vayunmathur/share/network/airdrop/AirDropHttp.kt b/share/src/main/java/com/vayunmathur/share/network/airdrop/AirDropHttp.ktindex f6885fe093..c4de0c1244 100644--- a/share/src/main/java/com/vayunmathur/share/network/airdrop/AirDropHttp.kt+++ b/share/src/main/java/com/vayunmathur/share/network/airdrop/AirDropHttp.kt@@ -32,6 +32,8 @@ object AirDropHttp {         val contentLength: Long? get() = this["content-length"]?.trim()?.toLongOrNull()         val isChunked: Boolean get() = this["transfer-encoding"]?.contains("chunked", ignoreCase = true) == true         val keepAlive: Boolean get() = this["connection"]?.equals("close", ignoreCase = true) != true+        /** Snapshot of the parsed headers; keys are lowercased, like [get] expects. */+        fun toMap(): Map<String, String> = LinkedHashMap(map)         override fun toString(): String = map.toString()     } @@ -65,7 +67,7 @@ object AirDropHttp {             "deflate" -> InflaterInputStream(raw)             else -> raw         }-        return Response(status, emptyMap(), readLimited(decoded, limit))+        return Response(status, headers.toMap(), readLimited(decoded, limit))     }      fun writeRequestHead(out: OutputStream, method: String, path: String, headers: List<Pair<String, String>>) {
share/src/test/java/com/vayunmathur/share/network/airdrop/AirDropHttpTest.kt
diff --git a/share/src/test/java/com/vayunmathur/share/network/airdrop/AirDropHttpTest.kt b/share/src/test/java/com/vayunmathur/share/network/airdrop/AirDropHttpTest.ktindex 5bcde12d10..264445ab28 100644--- a/share/src/test/java/com/vayunmathur/share/network/airdrop/AirDropHttpTest.kt+++ b/share/src/test/java/com/vayunmathur/share/network/airdrop/AirDropHttpTest.kt@@ -52,6 +52,22 @@ class AirDropHttpTest {         assertEquals("ok", ok.body.decodeToString())     } +    @Test+    fun `response round trips with its headers`() {+        val out = ByteArrayOutputStream()+        AirDropHttp.writeResponse(+            out,+            AirDropHttp.Response(+                200,+                mapOf("Content-Type" to "application/x-apple-binary-plist"),+                "ok".toByteArray(),+            ),+            keepAlive = true,+        )+        val resp = AirDropHttp.readResponse(ByteArrayInputStream(out.toByteArray()))+        assertEquals("application/x-apple-binary-plist", resp.headers["content-type"])+    }+     @Test     fun `self signed certificate parses and verifies`() {         val pair = KeyPairGenerator.getInstance("RSA").apply { initialize(2048) }.generateKeyPair()