Class Http2Session

java.lang.Object
org.glassfish.grizzly.http2.Http2Session

public class Http2Session extends Object
The HTTP2 session abstraction.
Author:
Alexey Stashok
  • Field Details

    • tmpHeaderFramesList

      protected final List<Http2Frame> tmpHeaderFramesList
  • Constructor Details

  • Method Details

    • get

      public static Http2Session get(Connection connection)
    • newOutputSink

      protected Http2SessionOutputSink 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 8192 is 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

      protected int getFrameSize(Buffer buffer)
      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

      public Http2Frame parseHttp2FrameHeader(Buffer buffer) throws Http2SessionException
      Throws:
      Http2SessionException
    • newStream

      protected Http2Stream newStream(HttpRequestPacket request, int streamId, int refStreamId, boolean exclusive, int priority)
    • newUpgradeStream

      protected Http2Stream newUpgradeStream(HttpRequestPacket request, int priority)
    • checkFrameSequenceSemantics

      protected void checkFrameSequenceSemantics(Http2Frame frame) throws Http2SessionException
      Throws:
      Http2SessionException
    • onOversizedFrame

      protected void onOversizedFrame(Buffer buffer) throws Http2SessionException
      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

      protected void setPeerMaxFramePayloadSize(int peerMaxFramePayloadSize) throws Http2SessionException
      Sets the max payload size to be accepted by the peer. The method is called during the SettingsFrame processing.
      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:
      true if push is enabled for this Http2Session, otherwise returns false. Push is enabled by default.
    • setPushEnabled

      public void setPushEnabled(boolean pushEnabled)
      Configure whether or not push is enabled on this Http2Session.
      Parameters:
      pushEnabled - flag toggling push support.
    • getNextLocalStreamId

      public int getNextLocalStreamId()
    • getConnection

      public Connection getConnection()
    • getMemoryManager

      public MemoryManager getMemoryManager()
    • isServer

      public boolean isServer()
    • isLocallyInitiatedStream

      public boolean isLocallyInitiatedStream(int streamId)
    • getStream

      public Http2Stream getStream(int streamId)
    • getOutputSink

      protected Http2SessionOutputSink 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 IOException
      Encodes the HttpHeader and locks the compression lock.
      Parameters:
      ctx - the current FilterChainContext
      httpHeader - the HttpHeader to encode
      streamId - the stream associated with this request
      isLast - is this the last frame?
      toList - the target List, 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 IOException
      Encodes the Map of header values into header frames to be sent as trailer headers.
      Parameters:
      streamId - the stream associated with this request
      toList - the target List, to which the frames will be serialized.
      trailerHeaders - a MimeHeaders of 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 IOException
      Encodes the HttpRequestPacket as a PushPromiseFrame and locks the compression lock.
      Parameters:
      ctx - the current FilterChainContext
      httpRequest - the HttpRequestPacket to encode.
      streamId - the stream associated with this request.
      promisedStreamId - the push promise stream ID.
      toList - the target List, to which the frames will be serialized
      Returns:
      the HTTP2 push promise frames sequence
      Throws:
      IOException - if an error occurs encoding the request
    • getNewClientStreamLock

      public ReentrantLock getNewClientStreamLock()
      The ReentrantLock, 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 within getNewClientStreamLock() lock scope. The caller code is responsible for obtaining and releasing the mentioned getNewClientStreamLock() lock.
      Parameters:
      request - the request that initiated the stream
      streamId - the ID of this new stream
      parentStreamId - the parent stream
      priority - the priority of this stream
      Returns:
      a new Http2Stream for 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 an Http2Stream initiated via HTTP/1.1 Upgrade mechanism.
      Parameters:
      request - the request that initiated the upgrade
      priority - the stream priority
      fin - is more content expected?
      Returns:
      a new Http2Stream for 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 upgrade
      priority - the priority of the stream
      Returns:
      a new Http2Stream for this request
      Throws:
      Http2StreamException - if an error occurs opening the stream.
    • prepareSettings

      protected SettingsFrame.SettingsFrameBuilder prepareSettings()