List of usage examples for io.netty.handler.codec.http2 Http2HeadersFrame isEndStream
boolean isEndStream();
From source file:com.flysoloing.learning.network.netty.http2.helloworld.multiplex.server.HelloWorldHttp2Handler.java
License:Apache License
/** * If receive a frame with end-of-stream set, send a pre-canned response. */// w w w .j a va2 s . c o m public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream()) { ByteBuf content = ctx.alloc().buffer(); content.writeBytes(RESPONSE_BYTES.duplicate()); ByteBufUtil.writeAscii(content, " - via HTTP/2"); sendResponse(ctx, content); } }
From source file:com.hop.hhxx.example.http2.helloworld.multiplex.server.HelloWorldHttp2Handler.java
License:Apache License
/** * If receive a frame with end-of-stream set, send a pre-canned response. *///www .jav a2 s .co m public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream()) { ByteBuf content = ctx.alloc().buffer(); content.writeBytes(RESPONSE_BYTES); ByteBufUtil.writeAscii(content, " - via HTTP/2"); sendResponse(ctx, content); } }
From source file:example.http2.helloworld.frame.server.HelloWorldHttp2Handler.java
License:Apache License
/** * If receive a frame with end-of-stream set, send a pre-canned response. *///from ww w . j a v a2 s . co m private static void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream()) { ByteBuf content = ctx.alloc().buffer(); content.writeBytes(RESPONSE_BYTES.duplicate()); ByteBufUtil.writeAscii(content, " - via HTTP/2"); sendResponse(ctx, headers.stream(), content); } }
From source file:example.http2.helloworld.multiplex.server.HelloWorldHttp2Handler.java
License:Apache License
/** * If receive a frame with end-of-stream set, send a pre-canned response. *//*from www . ja va 2 s.c o m*/ private static void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream()) { ByteBuf content = ctx.alloc().buffer(); content.writeBytes(RESPONSE_BYTES.duplicate()); ByteBufUtil.writeAscii(content, " - via HTTP/2"); sendResponse(ctx, content); } }
From source file:me.netty.http.handler.HelloWorldHttp2Handler.java
License:Apache License
/** * If receive a frame with end-of-stream set, send a pre-canned response. *///from ww w . java 2s . c o m public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream()) { ByteBuf content = ctx.alloc().buffer(); content.writeBytes(RESPONSE_BYTES.duplicate()); ByteBufUtil.writeAscii(content, " - via HTTP/2"); sendResponse(ctx, content); } logger.debug("get header stream id is : " + headers.streamId()); }
From source file:org.glassfish.jersey.netty.httpserver.JerseyHttp2ServerHandler.java
License:Open Source License
/** * Create Jersey {@link ContainerRequest} based on Netty {@link HttpRequest}. * * @param ctx Netty channel context. * @param http2Headers Netty Http/2 headers. * @return created Jersey Container Request. *//* ww w . j a v a 2 s . co m*/ private ContainerRequest createContainerRequest(ChannelHandlerContext ctx, Http2HeadersFrame http2Headers) { String path = http2Headers.headers().path().toString(); String s = path.startsWith("/") ? path.substring(1) : path; URI requestUri = URI.create(baseUri + ContainerUtils.encodeUnsafeCharacters(s)); ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, http2Headers.headers().method().toString(), getSecurityContext(), new PropertiesDelegate() { private final Map<String, Object> properties = new HashMap<>(); @Override public Object getProperty(String name) { return properties.get(name); } @Override public Collection<String> getPropertyNames() { return properties.keySet(); } @Override public void setProperty(String name, Object object) { properties.put(name, object); } @Override public void removeProperty(String name) { properties.remove(name); } }); // request entity handling. if (!http2Headers.isEndStream()) { ctx.channel().closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(Future<? super Void> future) throws Exception { isList.add(NettyInputStream.END_OF_INPUT_ERROR); } }); requestContext.setEntityStream(new NettyInputStream(isList)); } else { requestContext.setEntityStream(new InputStream() { @Override public int read() throws IOException { return -1; } }); } // copying headers from netty request to jersey container request context. for (CharSequence name : http2Headers.headers().names()) { requestContext.headers(name.toString(), mapToString(http2Headers.headers().getAll(name))); } return requestContext; }
From source file:org.wso2.carbon.http2.transport.util.Http2ClientHandler.java
License:Open Source License
/** * Read respond frames from netty channel and pass to ResponseReceiver * * @param ctx//from ww w . j ava 2 s . c o m * @param msg */ @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof Http2HeadersFrame) { Http2HeadersFrame frame = (Http2HeadersFrame) msg; if (!sentRequests.containsKey(frame.streamId())) { return; } receiver.onHeadersFrameRead(frame, sentRequests.get(frame.streamId())); if (frame.isEndStream()) { sentRequests.remove(frame.streamId()); } } else if (msg instanceof Http2DataFrame) { Http2DataFrame frame = (Http2DataFrame) msg; if (!sentRequests.containsKey(frame.streamId())) { return; } receiver.onDataFrameRead(frame, sentRequests.get(frame.streamId())); if (frame.isEndStream()) { sentRequests.remove(frame.streamId()); } } else if (msg instanceof Http2PushPromiseFrame) { Http2PushPromiseFrame frame = (Http2PushPromiseFrame) msg; if (!sentRequests.containsKey(frame.streamId())) { return; } MessageContext prevRequest = sentRequests.get(frame.streamId()); //if the inbound is not accept push requests reject them if (!receiver.isServerPushAccepted()) { writer.writeRestSreamRequest(frame.getPushPromiseId(), Http2Error.REFUSED_STREAM); return; } sentRequests.put(frame.getPushPromiseId(), prevRequest); receiver.onPushPromiseFrameRead(frame, prevRequest); } else if (msg instanceof Http2Settings) { setChContext(ctx); receiver.onUnknownFrameRead(msg); } else if (msg instanceof Http2GoAwayFrame) { receiver.onUnknownFrameRead(msg); } else if (msg instanceof Http2ResetFrame) { if (sentRequests.containsKey(((Http2ResetFrame) msg).streamId())) { sentRequests.remove(((Http2ResetFrame) msg).streamId()); } receiver.onUnknownFrameRead(msg); } else { receiver.onUnknownFrameRead(msg); } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.Http2RequestReader.java
License:Open Source License
/** * Handles header frames/*from w ww. j ava 2 s .c o m*/ * * @param frame */ public void onHeaderRead(Http2HeadersFrame frame) { Http2SourceRequest request; if (requestMap.containsKey(frame.streamId())) { request = requestMap.get(frame.streamId()); } else { request = new Http2SourceRequest(frame.streamId(), chContext); request.setRequestType(Http2Constants.HTTP2_CLIENT_SENT_REQEUST); requestMap.put(frame.streamId(), request); } Set<CharSequence> headerSet = frame.headers().names(); for (CharSequence header : headerSet) { request.setHeader(header.toString(), frame.headers().get(header).toString()); } if (frame.isEndStream()) { try { messageHandler.processRequest(request); requestMap.remove(frame.streamId()); } catch (Exception e) { log.error(e); } } }
From source file:org.wso2.esb.integration.common.utils.clients.http2client.Http2Response.java
License:Open Source License
public Http2Response(Http2HeadersFrame frame) { responseFromHttp2Server = true;/* w ww .j a va 2 s. c o m*/ if (frame.isEndStream()) { endOfStream = true; } Iterator<Map.Entry<CharSequence, CharSequence>> iterator = frame.headers().iterator(); while (iterator.hasNext()) { Map.Entry<CharSequence, CharSequence> header = iterator.next(); String key = header.getKey().toString(); key = (key.charAt(0) == ':') ? key.substring(1) : key; if (this.headers.containsKey(key)) { this.excessHeaders.put(key, header.getValue().toString()); } else { this.headers.put(key, header.getValue().toString()); } } if (headers.containsKey("status")) { status = Integer.parseInt(headers.get("status").toString()); } if (headers.containsKey(HttpHeaderNames.CONTENT_TYPE)) { expectResponseBody = true; } }
From source file:org.wso2.esb.integration.common.utils.servers.http2.Http2Handler.java
License:Open Source License
public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream() && (headers.headers().method().toString()).equalsIgnoreCase("GET")) { if (headers.headers().contains("http2-settings")) { return; }//from w ww. ja v a 2s.c o m Http2Headers headers1 = new DefaultHttp2Headers().status(OK.codeAsText()); ctx.writeAndFlush(new DefaultHttp2HeadersFrame(headers1)); } }