|
22 | 22 | import static io.netty.util.AsciiString.of;
|
23 | 23 | import static org.junit.Assert.assertEquals;
|
24 | 24 | import static org.junit.Assert.assertTrue;
|
| 25 | +import static org.junit.Assert.fail; |
25 | 26 |
|
26 | 27 | import com.google.common.collect.Iterables;
|
27 | 28 | import com.google.common.io.BaseEncoding;
|
@@ -133,6 +134,130 @@ public void decode_emptyHeaders() throws Http2Exception {
|
133 | 134 | assertThat(decodedHeaders.toString()).contains("[]");
|
134 | 135 | }
|
135 | 136 |
|
| 137 | + // contains() is used by Netty 4.1.75+. https://github.com/grpc/grpc-java/issues/8981 |
| 138 | + // Just implement everything pseudo headers for all methods; too many recent breakages. |
| 139 | + @Test |
| 140 | + public void grpcHttp2RequestHeaders_pseudoHeaders_notPresent() { |
| 141 | + Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2); |
| 142 | + assertThat(http2Headers.get(AsciiString.of(":path"))).isNull(); |
| 143 | + assertThat(http2Headers.get(AsciiString.of(":authority"))).isNull(); |
| 144 | + assertThat(http2Headers.get(AsciiString.of(":method"))).isNull(); |
| 145 | + assertThat(http2Headers.get(AsciiString.of(":scheme"))).isNull(); |
| 146 | + assertThat(http2Headers.get(AsciiString.of(":status"))).isNull(); |
| 147 | + |
| 148 | + assertThat(http2Headers.getAll(AsciiString.of(":path"))).isEmpty(); |
| 149 | + assertThat(http2Headers.getAll(AsciiString.of(":authority"))).isEmpty(); |
| 150 | + assertThat(http2Headers.getAll(AsciiString.of(":method"))).isEmpty(); |
| 151 | + assertThat(http2Headers.getAll(AsciiString.of(":scheme"))).isEmpty(); |
| 152 | + assertThat(http2Headers.getAll(AsciiString.of(":status"))).isEmpty(); |
| 153 | + |
| 154 | + assertThat(http2Headers.contains(AsciiString.of(":path"))).isFalse(); |
| 155 | + assertThat(http2Headers.contains(AsciiString.of(":authority"))).isFalse(); |
| 156 | + assertThat(http2Headers.contains(AsciiString.of(":method"))).isFalse(); |
| 157 | + assertThat(http2Headers.contains(AsciiString.of(":scheme"))).isFalse(); |
| 158 | + assertThat(http2Headers.contains(AsciiString.of(":status"))).isFalse(); |
| 159 | + |
| 160 | + assertThat(http2Headers.remove(AsciiString.of(":path"))).isFalse(); |
| 161 | + assertThat(http2Headers.remove(AsciiString.of(":authority"))).isFalse(); |
| 162 | + assertThat(http2Headers.remove(AsciiString.of(":method"))).isFalse(); |
| 163 | + assertThat(http2Headers.remove(AsciiString.of(":scheme"))).isFalse(); |
| 164 | + assertThat(http2Headers.remove(AsciiString.of(":status"))).isFalse(); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + public void grpcHttp2RequestHeaders_pseudoHeaders_present() { |
| 169 | + Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2); |
| 170 | + http2Headers.add(AsciiString.of(":path"), AsciiString.of("mypath")); |
| 171 | + http2Headers.add(AsciiString.of(":authority"), AsciiString.of("myauthority")); |
| 172 | + http2Headers.add(AsciiString.of(":method"), AsciiString.of("mymethod")); |
| 173 | + http2Headers.add(AsciiString.of(":scheme"), AsciiString.of("myscheme")); |
| 174 | + |
| 175 | + assertThat(http2Headers.get(AsciiString.of(":path"))).isEqualTo(AsciiString.of("mypath")); |
| 176 | + assertThat(http2Headers.get(AsciiString.of(":authority"))) |
| 177 | + .isEqualTo(AsciiString.of("myauthority")); |
| 178 | + assertThat(http2Headers.get(AsciiString.of(":method"))).isEqualTo(AsciiString.of("mymethod")); |
| 179 | + assertThat(http2Headers.get(AsciiString.of(":scheme"))).isEqualTo(AsciiString.of("myscheme")); |
| 180 | + |
| 181 | + assertThat(http2Headers.getAll(AsciiString.of(":path"))) |
| 182 | + .containsExactly(AsciiString.of("mypath")); |
| 183 | + assertThat(http2Headers.getAll(AsciiString.of(":authority"))) |
| 184 | + .containsExactly(AsciiString.of("myauthority")); |
| 185 | + assertThat(http2Headers.getAll(AsciiString.of(":method"))) |
| 186 | + .containsExactly(AsciiString.of("mymethod")); |
| 187 | + assertThat(http2Headers.getAll(AsciiString.of(":scheme"))) |
| 188 | + .containsExactly(AsciiString.of("myscheme")); |
| 189 | + |
| 190 | + assertThat(http2Headers.contains(AsciiString.of(":path"))).isTrue(); |
| 191 | + assertThat(http2Headers.contains(AsciiString.of(":authority"))).isTrue(); |
| 192 | + assertThat(http2Headers.contains(AsciiString.of(":method"))).isTrue(); |
| 193 | + assertThat(http2Headers.contains(AsciiString.of(":scheme"))).isTrue(); |
| 194 | + |
| 195 | + assertThat(http2Headers.remove(AsciiString.of(":path"))).isTrue(); |
| 196 | + assertThat(http2Headers.remove(AsciiString.of(":authority"))).isTrue(); |
| 197 | + assertThat(http2Headers.remove(AsciiString.of(":method"))).isTrue(); |
| 198 | + assertThat(http2Headers.remove(AsciiString.of(":scheme"))).isTrue(); |
| 199 | + |
| 200 | + assertThat(http2Headers.contains(AsciiString.of(":path"))).isFalse(); |
| 201 | + assertThat(http2Headers.contains(AsciiString.of(":authority"))).isFalse(); |
| 202 | + assertThat(http2Headers.contains(AsciiString.of(":method"))).isFalse(); |
| 203 | + assertThat(http2Headers.contains(AsciiString.of(":scheme"))).isFalse(); |
| 204 | + } |
| 205 | + |
| 206 | + @Test |
| 207 | + public void grpcHttp2RequestHeaders_pseudoHeaders_set() { |
| 208 | + Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2); |
| 209 | + http2Headers.set(AsciiString.of(":path"), AsciiString.of("mypath")); |
| 210 | + http2Headers.set(AsciiString.of(":authority"), AsciiString.of("myauthority")); |
| 211 | + http2Headers.set(AsciiString.of(":method"), AsciiString.of("mymethod")); |
| 212 | + http2Headers.set(AsciiString.of(":scheme"), AsciiString.of("myscheme")); |
| 213 | + |
| 214 | + assertThat(http2Headers.getAll(AsciiString.of(":path"))) |
| 215 | + .containsExactly(AsciiString.of("mypath")); |
| 216 | + assertThat(http2Headers.getAll(AsciiString.of(":authority"))) |
| 217 | + .containsExactly(AsciiString.of("myauthority")); |
| 218 | + assertThat(http2Headers.getAll(AsciiString.of(":method"))) |
| 219 | + .containsExactly(AsciiString.of("mymethod")); |
| 220 | + assertThat(http2Headers.getAll(AsciiString.of(":scheme"))) |
| 221 | + .containsExactly(AsciiString.of("myscheme")); |
| 222 | + |
| 223 | + http2Headers.set(AsciiString.of(":path"), AsciiString.of("mypath2")); |
| 224 | + http2Headers.set(AsciiString.of(":authority"), AsciiString.of("myauthority2")); |
| 225 | + http2Headers.set(AsciiString.of(":method"), AsciiString.of("mymethod2")); |
| 226 | + http2Headers.set(AsciiString.of(":scheme"), AsciiString.of("myscheme2")); |
| 227 | + |
| 228 | + assertThat(http2Headers.getAll(AsciiString.of(":path"))) |
| 229 | + .containsExactly(AsciiString.of("mypath2")); |
| 230 | + assertThat(http2Headers.getAll(AsciiString.of(":authority"))) |
| 231 | + .containsExactly(AsciiString.of("myauthority2")); |
| 232 | + assertThat(http2Headers.getAll(AsciiString.of(":method"))) |
| 233 | + .containsExactly(AsciiString.of("mymethod2")); |
| 234 | + assertThat(http2Headers.getAll(AsciiString.of(":scheme"))) |
| 235 | + .containsExactly(AsciiString.of("myscheme2")); |
| 236 | + } |
| 237 | + |
| 238 | + @Test |
| 239 | + public void grpcHttp2RequestHeaders_pseudoHeaders_addWhenPresent_throws() { |
| 240 | + Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2); |
| 241 | + http2Headers.add(AsciiString.of(":path"), AsciiString.of("mypath")); |
| 242 | + try { |
| 243 | + http2Headers.add(AsciiString.of(":path"), AsciiString.of("mypath2")); |
| 244 | + fail("Expected exception"); |
| 245 | + } catch (Exception ex) { |
| 246 | + // expected |
| 247 | + } |
| 248 | + } |
| 249 | + |
| 250 | + @Test |
| 251 | + public void grpcHttp2RequestHeaders_pseudoHeaders_addInvalid_throws() { |
| 252 | + Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2); |
| 253 | + try { |
| 254 | + http2Headers.add(AsciiString.of(":status"), AsciiString.of("mystatus")); |
| 255 | + fail("Expected exception"); |
| 256 | + } catch (Exception ex) { |
| 257 | + // expected |
| 258 | + } |
| 259 | + } |
| 260 | + |
136 | 261 | @Test
|
137 | 262 | public void dupBinHeadersWithComma() {
|
138 | 263 | Key<byte[]> key = Key.of("bytes-bin", BINARY_BYTE_MARSHALLER);
|
|
0 commit comments