io.netty.handler.codec.http2.HttpConversionUtil.ExtensionHeaderNames Java Examples
The following examples show how to use
io.netty.handler.codec.http2.HttpConversionUtil.ExtensionHeaderNames.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestAdapter.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
/** * Configures the headers in the specified Netty HTTP request. */ private void addHeadersToRequest(DefaultHttpRequest httpRequest, SdkHttpRequest request) { httpRequest.headers().add(HOST, getHostHeaderValue(request)); String scheme = request.getUri().getScheme(); if (Protocol.HTTP2 == protocol && !StringUtils.isBlank(scheme)) { httpRequest.headers().add(ExtensionHeaderNames.SCHEME.text(), scheme); } // Copy over any other headers already in our request request.headers().entrySet().stream() /* * Skip the Host header to avoid sending it twice, which will * interfere with some signing schemes. */ .filter(e -> !IGNORE_HEADERS.contains(e.getKey())) .forEach(e -> e.getValue().forEach(h -> httpRequest.headers().add(e.getKey(), h))); }
Example #2
Source File: ArmeriaHttpUtil.java From armeria with Apache License 2.0 | 6 votes |
private static void addHttp2Scheme(io.netty.handler.codec.http.HttpHeaders in, URI uri, RequestHeadersBuilder out) { final String value = uri.getScheme(); if (value != null) { out.add(HttpHeaderNames.SCHEME, value); return; } // Consume the Scheme extension header if present final CharSequence cValue = in.get(ExtensionHeaderNames.SCHEME.text()); if (cValue != null) { out.add(HttpHeaderNames.SCHEME, cValue.toString()); } else { out.add(HttpHeaderNames.SCHEME, "unknown"); } }
Example #3
Source File: ArmeriaHttpUtilTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void excludeBlacklistHeadersWhileHttp2ToHttp1() { final HttpHeaders in = HttpHeaders.builder() .add(HttpHeaderNames.TRAILER, "foo") .add(HttpHeaderNames.HOST, "bar") .add(HttpHeaderNames.PATH, "dummy") .add(HttpHeaderNames.METHOD, "dummy") .add(HttpHeaderNames.SCHEME, "dummy") .add(HttpHeaderNames.STATUS, "dummy") .add(HttpHeaderNames.TRANSFER_ENCODING, "dummy") .add(ExtensionHeaderNames.STREAM_ID.text(), "dummy") .add(ExtensionHeaderNames.SCHEME.text(), "dummy") .add(ExtensionHeaderNames.PATH.text(), "dummy") .build(); final io.netty.handler.codec.http.HttpHeaders out = new DefaultHttpHeaders(); toNettyHttp1ServerHeader(in, out); assertThat(out).isEqualTo(new DefaultHttpHeaders() .add(io.netty.handler.codec.http.HttpHeaderNames.TRAILER, "foo") .add(io.netty.handler.codec.http.HttpHeaderNames.HOST, "bar")); }
Example #4
Source File: Http2BackendHandler.java From nitmproxy with MIT License | 5 votes |
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { LOGGER.info("[Client ({})] => [Server ({})] : {}", connectionInfo.getClientAddr(), connectionInfo.getServerAddr(), msg); if (msg instanceof FullHttpRequest) { HttpMessage httpMessage = (HttpRequest) msg; httpMessage.headers().add(ExtensionHeaderNames.SCHEME.text(), "https"); } else if (msg instanceof HttpObject) { throw new IllegalStateException("Cannot handle message: " + msg.getClass()); } ctx.writeAndFlush(msg, promise); }
Example #5
Source File: THttp2Client.java From armeria with Apache License 2.0 | 5 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2Settings) { settingsPromise.setSuccess(null); return; } if (msg instanceof FullHttpResponse) { final FullHttpResponse res = (FullHttpResponse) msg; final Integer streamId = res.headers().getInt( HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text()); if (streamId == null) { responsePromise.tryFailure(new AssertionError("message without stream ID: " + msg)); return; } if (streamId == 1) { // Response to the upgrade request, which is OK to ignore. return; } if (streamId != 3) { responsePromise.tryFailure(new AssertionError("unexpected stream ID: " + msg)); return; } responsePromise.setSuccess(res.content().retain()); return; } throw new IllegalStateException("unexpected message type: " + msg.getClass().getName()); }