|
10 | 10 | import static org.hamcrest.Matchers.empty; |
11 | 11 | import static org.hamcrest.Matchers.equalTo; |
12 | 12 | import static org.hamcrest.Matchers.not; |
| 13 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
13 | 14 |
|
| 15 | +import java.io.ByteArrayInputStream; |
| 16 | +import java.io.InputStream; |
14 | 17 | import java.net.URI; |
15 | 18 | import java.net.URISyntaxException; |
| 19 | +import java.net.http.HttpClient; |
| 20 | +import java.net.http.HttpHeaders; |
| 21 | +import java.net.http.HttpRequest; |
| 22 | +import java.net.http.HttpResponse; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | +import java.util.Optional; |
| 26 | +import javax.net.ssl.SSLSession; |
16 | 27 | import org.junit.jupiter.api.AfterAll; |
17 | 28 | import org.junit.jupiter.api.BeforeAll; |
18 | 29 | import org.junit.jupiter.api.Test; |
@@ -91,4 +102,59 @@ public void automaticallyAppliesUserAgentPlugin() throws URISyntaxException { |
91 | 102 | // the interceptor is package-private, so this check will suffice. |
92 | 103 | assertThat(config.interceptors().toString(), containsString("UserAgentPlugin")); |
93 | 104 | } |
| 105 | + |
| 106 | + @Test |
| 107 | + public void filtersStatusPseudoHeaderFromResponse() throws Exception { |
| 108 | + // Create a fake Java HttpResponse with :status pseudo-header |
| 109 | + var fakeResponse = new HttpResponse<InputStream>() { |
| 110 | + @Override |
| 111 | + public int statusCode() { |
| 112 | + return 200; |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public HttpHeaders headers() { |
| 117 | + return HttpHeaders.of( |
| 118 | + Map.of(":status", List.of("200"), "content-type", List.of("application/json")), |
| 119 | + (k, v) -> true); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public InputStream body() { |
| 124 | + return new ByteArrayInputStream(new byte[0]); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public HttpClient.Version version() { |
| 129 | + return HttpClient.Version.HTTP_2; |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public HttpRequest request() { |
| 134 | + return null; |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public Optional<HttpResponse<InputStream>> previousResponse() { |
| 139 | + return Optional.empty(); |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public Optional<SSLSession> sslSession() { |
| 144 | + return Optional.empty(); |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public URI uri() { |
| 149 | + return URI.create("http://localhost/test"); |
| 150 | + } |
| 151 | + }; |
| 152 | + |
| 153 | + var transport = new JavaHttpClientTransport(); |
| 154 | + var response = transport.createSmithyResponse(fakeResponse); |
| 155 | + |
| 156 | + assertFalse(response.headers().map().containsKey(":status"), |
| 157 | + "Response headers should not contain :status pseudo-header"); |
| 158 | + assertThat(response.headers().firstValue("content-type"), equalTo("application/json")); |
| 159 | + } |
94 | 160 | } |
0 commit comments