-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-4943 NettyHttp2ApplicationResponse should not expose pseudo head…
…ers (#3186)
- Loading branch information
Showing
2 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...tor-server-netty/jvm/test/io/ktor/tests/server/netty/NettyHttp2ApplicationResponseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.tests.server.netty | ||
|
||
import io.ktor.http.* | ||
import io.ktor.server.netty.http2.* | ||
import io.netty.handler.codec.http2.* | ||
import kotlin.test.* | ||
|
||
class NettyHttp2ApplicationResponseTest { | ||
|
||
@Test | ||
fun testAllHeadersSkipPseudoHeaders() { | ||
val nettyHeaders = DefaultHttp2Headers() | ||
val headers = NettyHttp2ApplicationResponse.Http2ResponseHeaders(nettyHeaders) | ||
nettyHeaders.status("200") | ||
headers.append(HttpHeaders.ContentType, "text/plain") | ||
assertEquals(headersOf(HttpHeaders.ContentType.lowercase(), "text/plain"), headers.allValues()) | ||
} | ||
|
||
@Test | ||
fun testGetHeaderSkipPseudoHeaders() { | ||
val nettyHeaders = DefaultHttp2Headers() | ||
val headers = NettyHttp2ApplicationResponse.Http2ResponseHeaders(nettyHeaders) | ||
nettyHeaders.status("200") | ||
headers.append(HttpHeaders.ContentType, "text/plain") | ||
assertEquals("text/plain", headers[HttpHeaders.ContentType.lowercase()]) | ||
assertNull(headers[":status"]) | ||
} | ||
|
||
@Test | ||
fun testGetHeaderValuesSkipPseudoHeaders() { | ||
val nettyHeaders = DefaultHttp2Headers() | ||
val headers = NettyHttp2ApplicationResponse.Http2ResponseHeaders(nettyHeaders) | ||
nettyHeaders.status("200") | ||
headers.append(HttpHeaders.ContentType, "text/plain") | ||
assertEquals(listOf("text/plain"), headers.values(HttpHeaders.ContentType.lowercase())) | ||
assertEquals(emptyList(), headers.values(":status")) | ||
} | ||
|
||
@Test | ||
fun testAppendThrowsOnPseudoHeaders() { | ||
val nettyHeaders = DefaultHttp2Headers() | ||
val headers = NettyHttp2ApplicationResponse.Http2ResponseHeaders(nettyHeaders) | ||
headers.append(HttpHeaders.ContentType, "text/plain") | ||
assertFailsWith<IllegalHeaderNameException> { headers.append(":status", "200") } | ||
} | ||
} |