/** * Creates {@link Http2Session} with pre-configured initial-windows-size and * max-concurrent-streams * @param connection the TCP {@link Connection} * @param isServer flag indicating whether this connection is server side or not. * @return {@link Http2Session} */ protected Http2Session createHttp2Session(final Connection connection, final boolean isServer) { final Http2Session http2Session = new Http2Session(connection, isServer, this); final int initialWindowSize = configuration.getInitialWindowSize(); if (initialWindowSize != -1) { http2Session.setLocalStreamWindowSize(initialWindowSize); } final int maxConcurrentStreams = configuration.getMaxConcurrentStreams(); if (maxConcurrentStreams != -1) { http2Session.setLocalMaxConcurrentStreams(maxConcurrentStreams); } Http2Session.bind(connection, http2Session); return http2Session; }
void sendPreface() { if (!isPrefaceSent) { synchronized (sessionLock) { if (!isPrefaceSent) { if (isServer) { sendServerPreface(); } else { sendClientPreface(); } isPrefaceSent = true; if (!isServer) { // If it's HTTP2 client, which uses HTTP/1.1 upgrade mechanism - // it can have unacked user data sent from the server. // So it's right time to ack this data and let the server send // more data if needed. ackConsumedData(getStream(0), 0); } } } } }
/** * Encodes the {@link Map} of header values into header frames to be sent as trailer headers. * * @param streamId the stream associated with this request * @param toList the target {@link List}, to which the frames will be serialized. * @param trailerHeaders a {@link MimeHeaders} of headers to be transmitted as trailers. * * @return the HTTP2 header frames sequence * * @throws IOException if an error occurs encoding the header */ protected List<Http2Frame> encodeTrailersAsHeaderFrames(final int streamId, final List<Http2Frame> toList, final MimeHeaders trailerHeaders, final Map<String,String> capture) throws IOException { final Buffer compressedHeaders = EncoderUtils.encodeTrailerHeaders(this, trailerHeaders, capture); return bufferToHeaderFrames(streamId, compressedHeaders, true, toList); }
private Http2State doDirectUpgrade(final FilterChainContext ctx) { final Connection connection = ctx.getConnection(); final Http2Session http2Session = new Http2Session(connection, true, this); // Create HTTP/2.0 connection for the given Grizzly Connection final Http2State http2State = Http2State.create(connection); http2State.setHttp2Session(http2Session); http2State.setDirectUpgradePhase(); http2Session.setupFilterChains(ctx, true); // server preface http2Session.sendPreface(); return http2State; }
new Http2Session(connection, true, this); http2Session.setupFilterChains(ctx, true); http2Session.sendPreface(); httpResponse.getProcessingState().setKeepAlive(true); if (http2Session.isGoingAway()) { Http2State.remove(connection); return false; final Http2Stream stream = http2Session.acceptUpgradeStream( httpRequest, 0, !httpRequest.isExpectContent());
decStreamCount(); isCloseSession = isGoingAway() && concurrentStreamsCount == 0; if (!isCloseSession) { if (checkCount++ > http2Configuration.getCleanFrequencyCheck() && streamsMap.size() > streamsHighWaterMark) { sessionClosed.result(this); } else { terminate(ErrorCode.NO_ERROR, "Session closed");
throws Http2StreamException, IOException { if (http2Session.isGoingAway()) { return; final Http2Stream refStream = http2Session.getStream(refStreamId); if (refStream == null) { throw new Http2StreamException(refStreamId, ErrorCode.REFUSED_STREAM, final Http2Stream stream = http2Session.acceptStream(request, pushPromiseFrame.getPromisedStreamId(), refStreamId, false, 0);
request.setConnection(context.getConnection()); Http2Stream stream = http2Session.getStream(headersFrame.getStreamId()); if (stream != null) { final Http2Stream.State state = stream.getState(); stream = http2Session.acceptStream(request, headersFrame.getStreamId(), headersFrame.getStreamDependency(),
/** * Encodes a compressed header buffer as a {@link HeadersFrame} and * a sequence of 0 or more {@link ContinuationFrame}s. * * @param streamId the stream associated with the headers. * @param compressedHeaders a {@link Buffer} containing compressed headers * @param isEos will any additional data be sent after these headers? * @param toList the {@link List} to which {@link Http2Frame}s will be added * @return the result {@link List} with the frames */ private List<Http2Frame> bufferToHeaderFrames(final int streamId, final Buffer compressedHeaders, final boolean isEos, final List<Http2Frame> toList) { final HeadersFrame.HeadersFrameBuilder builder = HeadersFrame.builder() .streamId(streamId) .endStream(isEos); return completeHeadersProviderFrameSerialization(builder, streamId, compressedHeaders, toList); }
/** * Acknowledge that certain amount of data has been read. * Depending on the total amount of un-acknowledge data the HTTP2 connection * can decide to send a window_update message to the peer. * * @param sz size, in bytes, of the data being acknowledged */ void ackConsumedData(final int sz) { ackConsumedData(null, sz); }
bufferToPushPromiseFrames( streamId, promisedStreamId,
throws Http2StreamException, Http2SessionException, IOException { http2Session.checkFrameSequenceSemantics(frame);
new Http2Session(connection, true, this); http2Session.setupFilterChains(ctx, true); http2Session.sendPreface(); httpResponse.getProcessingState().setKeepAlive(true); if (http2Session.isGoingAway()) { Http2State.remove(connection); return false; final Http2Stream stream = http2Session.acceptUpgradeStream( httpRequest, 0, !httpRequest.isExpectContent());
private Http2State doDirectUpgrade(final FilterChainContext ctx) { final Connection connection = ctx.getConnection(); final Http2Session http2Session = new Http2Session(connection, true, this); // Create HTTP/2.0 connection for the given Grizzly Connection final Http2State http2State = Http2State.create(connection); http2State.setHttp2Session(http2Session); http2State.setDirectUpgradePhase(); http2Session.setupFilterChains(ctx, true); // server preface http2Session.sendPreface(); return http2State; }
decStreamCount(); isCloseSession = isGoingAway() && concurrentStreamsCount == 0; if (!isCloseSession) { if (checkCount++ > http2Configuration.getCleanFrequencyCheck() && streamsMap.size() > streamsHighWaterMark) { sessionClosed.result(this); } else { terminate(ErrorCode.NO_ERROR, "Session closed");
throws Http2StreamException, IOException { if (http2Session.isGoingAway()) { return; final Http2Stream refStream = http2Session.getStream(refStreamId); if (refStream == null) { throw new Http2StreamException(refStreamId, ErrorCode.REFUSED_STREAM, final Http2Stream stream = http2Session.acceptStream(request, pushPromiseFrame.getPromisedStreamId(), refStreamId, false, 0);
request.setConnection(context.getConnection()); Http2Stream stream = http2Session.getStream(headersFrame.getStreamId()); if (stream != null) { final Http2Stream.State state = stream.getState(); stream = http2Session.acceptStream(request, headersFrame.getStreamId(), headersFrame.getStreamDependency(),
/** * Encodes a compressed header buffer as a {@link PushPromiseFrame} and * a sequence of 0 or more {@link ContinuationFrame}s. * * @param streamId the stream associated with these headers * @param promisedStreamId the stream of the push promise * @param compressedHeaders the compressed headers to be sent * @param toList the {@link List} to which {@link Http2Frame}s will be added * @return the result {@link List} with the frames */ private List<Http2Frame> bufferToPushPromiseFrames(final int streamId, final int promisedStreamId, final Buffer compressedHeaders, final List<Http2Frame> toList) { final PushPromiseFrame.PushPromiseFrameBuilder builder = PushPromiseFrame.builder() .streamId(streamId) .promisedStreamId(promisedStreamId); return completeHeadersProviderFrameSerialization(builder, streamId, compressedHeaders, toList); }
/** * Acknowledge that certain amount of data has been read. * Depending on the total amount of un-acknowledge data the HTTP2 connection * can decide to send a window_update message to the peer. * * @param sz size, in bytes, of the data being acknowledged */ void ackConsumedData(final int sz) { ackConsumedData(null, sz); }
bufferToPushPromiseFrames( streamId, promisedStreamId,