List of usage examples for io.netty.handler.codec.http2 Http2Headers getAndRemove
V getAndRemove(K name);
From source file:org.wso2.carbon.transport.http.netty.listener.http2.HTTP2SourceHandler.java
License:Open Source License
/** * Setup carbon message for HTTP2 request. * * @param streamId Stream id of HTTP2 request received * @param headers HTTP2 Headers//from w ww. j a v a 2 s . c om * @return HTTPCarbonMessage */ protected HTTPCarbonMessage setupCarbonMessage(int streamId, Http2Headers headers) { // Construct new HTTP carbon message and put into stream id request map // TODO: This fix is temporary and we need to revisit this and the entire http2 implementation. HTTPCarbonMessage cMsg = new HTTPCarbonMessage( new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "")); cMsg.setProperty(Constants.PORT, ((InetSocketAddress) ctx.channel().remoteAddress()).getPort()); cMsg.setProperty(Constants.HOST, ((InetSocketAddress) ctx.channel().remoteAddress()).getHostName()); cMsg.setProperty(Constants.SCHEME, listenerConfiguration.getScheme()); cMsg.setProperty(Constants.HTTP_VERSION, Constants.HTTP2_VERSION); cMsg.setProperty(org.wso2.carbon.messaging.Constants.LISTENER_PORT, ((InetSocketAddress) ctx.channel().localAddress()).getPort()); cMsg.setProperty(org.wso2.carbon.messaging.Constants.LISTENER_INTERFACE_ID, listenerConfiguration.getId()); cMsg.setProperty(org.wso2.carbon.messaging.Constants.PROTOCOL, Constants.HTTP_SCHEME); if (listenerConfiguration.getSslConfig() != null) { cMsg.setProperty(Constants.IS_SECURED_CONNECTION, true); } else { cMsg.setProperty(Constants.IS_SECURED_CONNECTION, false); } cMsg.setProperty(Constants.LOCAL_ADDRESS, ctx.channel().localAddress()); cMsg.setProperty(Constants.LOCAL_NAME, ((InetSocketAddress) ctx.channel().localAddress()).getHostName()); cMsg.setProperty(Constants.REMOTE_ADDRESS, ctx.channel().remoteAddress()); cMsg.setProperty(Constants.REMOTE_HOST, ((InetSocketAddress) ctx.channel().remoteAddress()).getHostName()); cMsg.setProperty(Constants.REMOTE_PORT, ((InetSocketAddress) ctx.channel().remoteAddress()).getPort()); ChannelHandler handler = ctx.handler(); cMsg.setProperty(Constants.CHANNEL_ID, ((HTTP2SourceHandler) handler).getListenerConfiguration().getId()); cMsg.setProperty(Constants.STREAM_ID, streamId); if (headers.path() != null) { String path = headers.getAndRemove(Constants.HTTP2_PATH).toString(); cMsg.setProperty(Constants.TO, path); cMsg.setProperty(Constants.REQUEST_URL, path); } if (headers.method() != null) { String method = headers.getAndRemove(Constants.HTTP2_METHOD).toString(); cMsg.setProperty(Constants.HTTP_METHOD, method); } // Remove PseudoHeaderNames from headers headers.getAndRemove(Constants.HTTP2_AUTHORITY); headers.getAndRemove(Constants.HTTP2_SCHEME); // Copy Http2 headers to carbon message headers.forEach(k -> cMsg.setHeader(k.getKey().toString(), k.getValue().toString())); streamIdRequestMap.put(streamId, cMsg); return cMsg; }