@Override Http2StreamHandler createRemotelyInitiatedStream( final Http2StreamChannel channel, final HttpProcessor httpProcessor, final BasicHttpConnectionMetrics connMetrics, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) throws IOException { final HttpCoreContext context = HttpCoreContext.create(); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); return new ServerHttp2StreamHandler(channel, httpProcessor, connMetrics, exchangeHandlerFactory, context); }
@Override Http2StreamHandler createRemotelyInitiatedStream( final Http2StreamChannel channel, final HttpProcessor httpProcessor, final BasicHttpConnectionMetrics connMetrics, final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) throws IOException { final HttpCoreContext context = HttpCoreContext.create(); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); return new ClientPushHttp2StreamHandler(channel, httpProcessor, connMetrics, pushHandlerFactory != null ? pushHandlerFactory : this.pushHandlerFactory, context); }
@Override void execute(final RequestExecutionCommand executionCommand) throws HttpException, IOException { final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler(); final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext()); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); final ClientHttp1StreamHandler handler = new ClientHttp1StreamHandler( outputChannel, httpProcessor, h1Config, connectionReuseStrategy, exchangeHandler, context); pipeline.add(handler); outgoing = handler; if (handler.isOutputReady()) { handler.produceOutput(); } }
@Override void execute(final RequestExecutionCommand executionCommand) throws HttpException, IOException { final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler(); final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext()); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); final ClientHttp1StreamHandler handler = new ClientHttp1StreamHandler( outputChannel, httpProcessor, h1Config, connectionReuseStrategy, exchangeHandler, context); pipeline.add(handler); outgoing = handler; if (handler.isOutputReady()) { handler.produceOutput(); } }
@Override Http2StreamHandler createLocallyInitiatedStream( final ExecutableCommand command, final Http2StreamChannel channel, final HttpProcessor httpProcessor, final BasicHttpConnectionMetrics connMetrics) throws IOException { if (command instanceof RequestExecutionCommand) { final RequestExecutionCommand executionCommand = (RequestExecutionCommand) command; final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler(); final HandlerFactory<AsyncPushConsumer> pushHandlerFactory = executionCommand.getPushHandlerFactory(); final HttpCoreContext context = HttpCoreContext.adapt(executionCommand.getContext()); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); return new ClientHttp2StreamHandler(channel, httpProcessor, connMetrics, exchangeHandler, pushHandlerFactory != null ? pushHandlerFactory : this.pushHandlerFactory, context); } throw new H2ConnectionException(H2Error.INTERNAL_ERROR, "Unexpected executable command"); }
private void commitPromise( final HttpRequest promise, final AsyncPushProducer pushProducer) throws HttpException, IOException { context.setProtocolVersion(HttpVersion.HTTP_2); context.setAttribute(HttpCoreContext.HTTP_REQUEST, promise); httpProcessor.process(promise, null, context); final List<Header> headers = DefaultH2RequestConverter.INSTANCE.convert(promise); outputChannel.push(headers, pushProducer); connMetrics.incrementRequestCount(); }
private void commitResponse( final HttpResponse response, final EntityDetails responseEntityDetails) throws HttpException, IOException { if (responseCommitted.compareAndSet(false, true)) { context.setProtocolVersion(HttpVersion.HTTP_2); context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, responseEntityDetails, context); final List<Header> headers = DefaultH2ResponseConverter.INSTANCE.convert(response); outputChannel.submit(headers, responseEntityDetails == null); connMetrics.incrementResponseCount(); if (responseEntityDetails == null) { responseState = MessageState.COMPLETE; } else { responseState = MessageState.BODY; pushProducer.produce(outputChannel); } } }
@Override public void push(final List<Header> headers, final AsyncPushProducer pushProducer) throws HttpException, IOException { acceptPushRequest(); final int promisedStreamId = generateStreamId(); final Http2StreamChannelImpl channel = new Http2StreamChannelImpl( promisedStreamId, true, localConfig.getInitialWindowSize(), remoteConfig.getInitialWindowSize()); final HttpCoreContext context = HttpCoreContext.create(); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); final Http2StreamHandler streamHandler = new ServerPushHttp2StreamHandler( channel, httpProcessor, connMetrics, pushProducer, context); final Http2Stream stream = new Http2Stream(channel, streamHandler, false); streamMap.put(promisedStreamId, stream); ioSession.getLock().lock(); try { if (localEndStream) { stream.releaseResources(); return; } commitPushPromise(id, promisedStreamId, headers); idle = false; } finally { ioSession.getLock().unlock(); } }
@Override void consumeHeader(final HttpRequest request, final EntityDetails entityDetails) throws HttpException, IOException { if (streamListener != null) { streamListener.onRequestHead(this, request); } final ServerHttp1StreamHandler streamHandler; final HttpCoreContext context = HttpCoreContext.create(); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); if (outgoing == null) { streamHandler = new ServerHttp1StreamHandler( outputChannel, httpProcessor, connectionReuseStrategy, exchangeHandlerFactory, context); outgoing = streamHandler; } else { streamHandler = new ServerHttp1StreamHandler( new DelayedOutputChannel(outputChannel), httpProcessor, connectionReuseStrategy, exchangeHandlerFactory, context); pipeline.add(streamHandler); } request.setScheme(scheme); streamHandler.consumeHeader(request, entityDetails); incoming = streamHandler; }
@Override void consumeHeader(final HttpRequest request, final EntityDetails entityDetails) throws HttpException, IOException { if (streamListener != null) { streamListener.onRequestHead(this, request); } final ServerHttp1StreamHandler streamHandler; final HttpCoreContext context = HttpCoreContext.create(); context.setAttribute(HttpCoreContext.SSL_SESSION, getSSLSession()); context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, getEndpointDetails()); if (outgoing == null) { streamHandler = new ServerHttp1StreamHandler( outputChannel, httpProcessor, connectionReuseStrategy, exchangeHandlerFactory, context); outgoing = streamHandler; } else { streamHandler = new ServerHttp1StreamHandler( new DelayedOutputChannel(outputChannel), httpProcessor, connectionReuseStrategy, exchangeHandlerFactory, context); pipeline.add(streamHandler); } request.setScheme(scheme); streamHandler.consumeHeader(request, entityDetails); incoming = streamHandler; }
private void commitRequest(final HttpRequest request, final EntityDetails entityDetails) throws HttpException, IOException { if (requestCommitted.compareAndSet(false, true)) { context.setProtocolVersion(HttpVersion.HTTP_2); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); httpProcessor.process(request, entityDetails, context); final List<Header> headers = DefaultH2RequestConverter.INSTANCE.convert(request); outputChannel.submit(headers, entityDetails == null); connMetrics.incrementRequestCount(); if (entityDetails == null) { requestState = MessageState.COMPLETE; } else { final Header h = request.getFirstHeader(HttpHeaders.EXPECT); final boolean expectContinue = h != null && "100-continue".equalsIgnoreCase(h.getValue()); if (expectContinue) { requestState = MessageState.ACK; } else { requestState = MessageState.BODY; exchangeHandler.produce(dataChannel); } } } else { throw new H2ConnectionException(H2Error.INTERNAL_ERROR, "Request already committed"); } }
private void commitResponse( final HttpResponse response, final EntityDetails responseEntityDetails) throws HttpException, IOException { if (responseCommitted.compareAndSet(false, true)) { final int status = response.getCode(); if (status < HttpStatus.SC_SUCCESS) { throw new HttpException("Invalid response: " + status); } context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, responseEntityDetails, context); final List<Header> responseHeaders = DefaultH2ResponseConverter.INSTANCE.convert(response); Asserts.notNull(receivedRequest, "Received request"); final String method = receivedRequest.getMethod(); final boolean endStream = responseEntityDetails == null || method.equalsIgnoreCase("HEAD"); outputChannel.submit(responseHeaders, endStream); connMetrics.incrementResponseCount(); if (responseEntityDetails == null) { responseState = MessageState.COMPLETE; } else { responseState = MessageState.BODY; exchangeHandler.produce(outputChannel); } } else { throw new H2ConnectionException(H2Error.INTERNAL_ERROR, "Response already committed"); } }
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, responseEntityDetails, context);
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, responseEntityDetails, context);
context.setProtocolVersion(transportVersion); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
@Override public void consumeHeader(final List<Header> headers, final boolean endStream) throws HttpException, IOException { if (responseState == MessageState.HEADERS) { Asserts.notNull(request, "Request"); Asserts.notNull(exchangeHandler, "Exchange handler"); final HttpResponse response = DefaultH2ResponseConverter.INSTANCE.convert(headers); final EntityDetails entityDetails = endStream ? null : new IncomingEntityDetails(request, -1); context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, entityDetails, context); connMetrics.incrementResponseCount(); exchangeHandler.consumePromise(request, response, entityDetails, context); if (endStream) { responseState = MessageState.COMPLETE; exchangeHandler.streamEnd(null); } else { responseState = MessageState.BODY; } } else { throw new ProtocolException("Unexpected message headers"); } }
context.setProtocolVersion(transportVersion); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
@Override public void consumePromise(final List<Header> headers) throws HttpException, IOException { if (requestState == MessageState.HEADERS) { request = DefaultH2RequestConverter.INSTANCE.convert(headers); final AsyncPushConsumer handler; try { handler = pushHandlerFactory != null ? pushHandlerFactory.create(request, context) : null; } catch (final ProtocolException ex) { throw new H2StreamResetException(H2Error.PROTOCOL_ERROR, ex.getMessage()); } if (handler == null) { throw new H2StreamResetException(H2Error.REFUSED_STREAM, "Stream refused"); } exchangeHandler = handler; context.setProtocolVersion(HttpVersion.HTTP_2); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); httpProcessor.process(request, null, context); connMetrics.incrementRequestCount(); this.requestState = MessageState.COMPLETE; } else { throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Unexpected promise"); } }
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, entityDetails, context); connMetrics.incrementResponseCount();
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); httpProcessor.process(response, entityDetails, context);