Package org.glassfish.grizzly.http2
Class Http2Session
java.lang.Object
org.glassfish.grizzly.http2.Http2Session
The HTTP2 session abstraction.
- Author:
- Alexey Stashok
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttp2Session(Connection<?> connection, boolean isServer, Http2BaseFilter handlerFilter) -
Method Summary
Modifier and TypeMethodDescriptionacceptUpgradeStream(HttpRequestPacket request, int priority, boolean fin) The method is called to create anHttp2Streaminitiated via HTTP/1.1 Upgrade mechanism.protected voidprotected List<Http2Frame>encodeHttpHeaderAsHeaderFrames(FilterChainContext ctx, HttpHeader httpHeader, int streamId, boolean isLast, List<Http2Frame> toList, Map<String, String> capture) Encodes theHttpHeaderand locks the compression lock.protected List<Http2Frame>encodeHttpRequestAsPushPromiseFrames(FilterChainContext ctx, HttpRequestPacket httpRequest, int streamId, int promisedStreamId, List<Http2Frame> toList, Map<String, String> capture) Encodes theHttpRequestPacketas aPushPromiseFrameand locks the compression lock.protected List<Http2Frame>encodeTrailersAsHeaderFrames(int streamId, List<Http2Frame> toList, MimeHeaders trailerHeaders, Map<String, String> capture) Encodes theMapof header values into header frames to be sent as trailer headers.static Http2Sessionget(Connection connection) intintintintprotected intgetFrameSize(Buffer buffer) Returns the total frame size (including header size), or -1 if the buffer doesn't contain enough bytes to read the size.intintintfinal intintintTheReentrantLock, which assures that requests assigned to newly allocated stream IDs will be sent to the server in their order.intprotected Http2SessionOutputSinkintintintprotected intprotected intprotected intgetStream(int streamId) booleanisLocallyInitiatedStream(int streamId) booleanbooleanisServer()protected Http2SessionOutputSinkprotected Http2StreamnewStream(HttpRequestPacket request, int streamId, int refStreamId, boolean exclusive, int priority) protected Http2StreamnewUpgradeStream(HttpRequestPacket request, int priority) protected voidonOversizedFrame(Buffer buffer) openStream(HttpRequestPacket request, int streamId, int parentStreamId, boolean exclusive, int priority) Method is not thread-safe, it is expected that it will be called withingetNewClientStreamLock()lock scope.openUpgradeStream(HttpRequestPacket request, int priority) The method is called on the client side, when the server confirms HTTP/1.1 -> HTTP/2.0 upgrade with '101' response.parseHttp2FrameHeader(Buffer buffer) protected SettingsFrame.SettingsFrameBuilderprotected voidprotected voidprotected voidsendWindowUpdate(int streamId, int delta) voidsetLocalConnectionWindowSize(int localConnectionWindowSize) voidsetLocalMaxConcurrentStreams(int localMaxConcurrentStreams) Sets the default maximum number of concurrent streams allowed for this session by our side.voidsetLocalStreamWindowSize(int localStreamWindowSize) voidsetMaxHeaderListSize(int maxHeaderListSize) Set the maximum size, in bytes, of the header list.protected voidsetPeerMaxFramePayloadSize(int peerMaxFramePayloadSize) Sets the max payload size to be accepted by the peer.voidsetPushEnabled(boolean pushEnabled) Configure whether or not push is enabled on thisHttp2Session.
-
Field Details
-
tmpHeaderFramesList
-
-
Constructor Details
-
Http2Session
-
-
Method Details
-
get
-
newOutputSink
-
getSpecDefaultFramePayloadSize
protected int getSpecDefaultFramePayloadSize() -
getSpecMinFramePayloadSize
protected int getSpecMinFramePayloadSize() -
getSpecMaxFramePayloadSize
protected int getSpecMaxFramePayloadSize() -
getDefaultConnectionWindowSize
public int getDefaultConnectionWindowSize() -
getDefaultStreamWindowSize
public int getDefaultStreamWindowSize() -
getDefaultMaxConcurrentStreams
public int getDefaultMaxConcurrentStreams() -
getMaxHeaderListSize
public int getMaxHeaderListSize()- Returns:
- the maximum size, in bytes, of header list. If not explicitly configured, the default of
8192is used.
-
setMaxHeaderListSize
public void setMaxHeaderListSize(int maxHeaderListSize) Set the maximum size, in bytes, of the header list.- Parameters:
maxHeaderListSize- size, in bytes, of the header list.
-
getFrameSize
Returns the total frame size (including header size), or -1 if the buffer doesn't contain enough bytes to read the size.- Parameters:
buffer- the buffer containing the frame data- Returns:
- the total frame size (including header size), or -1 if the buffer doesn't contain enough bytes to read the size
-
parseHttp2FrameHeader
- Throws:
Http2SessionException
-
newStream
protected Http2Stream newStream(HttpRequestPacket request, int streamId, int refStreamId, boolean exclusive, int priority) -
newUpgradeStream
-
checkFrameSequenceSemantics
- Throws:
Http2SessionException
-
onOversizedFrame
- Throws:
Http2SessionException
-
getLocalMaxFramePayloadSize
public final int getLocalMaxFramePayloadSize()- Returns:
- The max payload size to be accepted by this side
-
getPeerMaxFramePayloadSize
public int getPeerMaxFramePayloadSize()- Returns:
- The max payload size to be accepted by the peer
-
setPeerMaxFramePayloadSize
Sets the max payload size to be accepted by the peer. The method is called during theSettingsFrameprocessing.- Parameters:
peerMaxFramePayloadSize- max payload size accepted by the peer.- Throws:
Http2SessionException- if the peerMaxFramePayloadSize violates the limits
-
getLocalStreamWindowSize
public int getLocalStreamWindowSize() -
setLocalStreamWindowSize
public void setLocalStreamWindowSize(int localStreamWindowSize) -
getPeerStreamWindowSize
public int getPeerStreamWindowSize() -
getLocalConnectionWindowSize
public int getLocalConnectionWindowSize() -
setLocalConnectionWindowSize
public void setLocalConnectionWindowSize(int localConnectionWindowSize) -
getAvailablePeerConnectionWindowSize
public int getAvailablePeerConnectionWindowSize() -
getLocalMaxConcurrentStreams
public int getLocalMaxConcurrentStreams()- Returns:
- the maximum number of concurrent streams allowed for this session by our side.
-
setLocalMaxConcurrentStreams
public void setLocalMaxConcurrentStreams(int localMaxConcurrentStreams) Sets the default maximum number of concurrent streams allowed for this session by our side.- Parameters:
localMaxConcurrentStreams- max number of streams locally allowed
-
getPeerMaxConcurrentStreams
public int getPeerMaxConcurrentStreams()- Returns:
- the maximum number of concurrent streams allowed for this session by peer.
-
isPushEnabled
public boolean isPushEnabled()- Returns:
trueif push is enabled for thisHttp2Session, otherwise returnsfalse. Push is enabled by default.
-
setPushEnabled
public void setPushEnabled(boolean pushEnabled) Configure whether or not push is enabled on thisHttp2Session.- Parameters:
pushEnabled- flag toggling push support.
-
getNextLocalStreamId
public int getNextLocalStreamId() -
getConnection
-
getMemoryManager
-
isServer
public boolean isServer() -
isLocallyInitiatedStream
public boolean isLocallyInitiatedStream(int streamId) -
getStream
-
getOutputSink
-
getGoingAwayLastStreamId
public int getGoingAwayLastStreamId() -
sendWindowUpdate
protected void sendWindowUpdate(int streamId, int delta) -
sendServerPreface
protected void sendServerPreface() -
sendClientPreface
protected void sendClientPreface() -
encodeHttpHeaderAsHeaderFrames
protected List<Http2Frame> encodeHttpHeaderAsHeaderFrames(FilterChainContext ctx, HttpHeader httpHeader, int streamId, boolean isLast, List<Http2Frame> toList, Map<String, String> capture) throws IOExceptionEncodes theHttpHeaderand locks the compression lock.- Parameters:
ctx- the currentFilterChainContexthttpHeader- theHttpHeaderto encodestreamId- the stream associated with this requestisLast- is this the last frame?toList- the targetList, to which the frames will be serialized- Returns:
- the HTTP2 header frames sequence
- Throws:
IOException- if an error occurs encoding the header
-
encodeTrailersAsHeaderFrames
protected List<Http2Frame> encodeTrailersAsHeaderFrames(int streamId, List<Http2Frame> toList, MimeHeaders trailerHeaders, Map<String, String> capture) throws IOExceptionEncodes theMapof header values into header frames to be sent as trailer headers.- Parameters:
streamId- the stream associated with this requesttoList- the targetList, to which the frames will be serialized.trailerHeaders- aMimeHeadersof headers to be transmitted as trailers.- Returns:
- the HTTP2 header frames sequence
- Throws:
IOException- if an error occurs encoding the header
-
encodeHttpRequestAsPushPromiseFrames
protected List<Http2Frame> encodeHttpRequestAsPushPromiseFrames(FilterChainContext ctx, HttpRequestPacket httpRequest, int streamId, int promisedStreamId, List<Http2Frame> toList, Map<String, String> capture) throws IOExceptionEncodes theHttpRequestPacketas aPushPromiseFrameand locks the compression lock.- Parameters:
ctx- the currentFilterChainContexthttpRequest- theHttpRequestPacketto encode.streamId- the stream associated with this request.promisedStreamId- the push promise stream ID.toList- the targetList, to which the frames will be serialized- Returns:
- the HTTP2 push promise frames sequence
- Throws:
IOException- if an error occurs encoding the request
-
getNewClientStreamLock
TheReentrantLock, which assures that requests assigned to newly allocated stream IDs will be sent to the server in their order. So that request associated with the stream ID '5' won't be sent before the request associated with the stream ID '3' etc.- Returns:
- the
ReentrantLock
-
openStream
public Http2Stream openStream(HttpRequestPacket request, int streamId, int parentStreamId, boolean exclusive, int priority) throws Http2StreamException Method is not thread-safe, it is expected that it will be called withingetNewClientStreamLock()lock scope. The caller code is responsible for obtaining and releasing the mentionedgetNewClientStreamLock()lock.- Parameters:
request- the request that initiated the streamstreamId- the ID of this new streamparentStreamId- the parent streampriority- the priority of this stream- Returns:
- a new
Http2Streamfor this request - Throws:
Http2StreamException- if an error occurs opening the stream.
-
acceptUpgradeStream
public Http2Stream acceptUpgradeStream(HttpRequestPacket request, int priority, boolean fin) throws Http2StreamException The method is called to create anHttp2Streaminitiated via HTTP/1.1 Upgrade mechanism.- Parameters:
request- the request that initiated the upgradepriority- the stream priorityfin- is more content expected?- Returns:
- a new
Http2Streamfor this request - Throws:
Http2StreamException- if an error occurs opening the stream.
-
openUpgradeStream
public Http2Stream openUpgradeStream(HttpRequestPacket request, int priority) throws Http2StreamException The method is called on the client side, when the server confirms HTTP/1.1 -> HTTP/2.0 upgrade with '101' response.- Parameters:
request- the request that initiated the upgradepriority- the priority of the stream- Returns:
- a new
Http2Streamfor this request - Throws:
Http2StreamException- if an error occurs opening the stream.
-
prepareSettings
-