Class HttpOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>

java.lang.Object
reactor.netty.channel.ChannelOperations<INBOUND,OUTBOUND>
reactor.netty.http.HttpOperations<INBOUND,OUTBOUND>
All Implemented Interfaces:
Publisher<Void>, Subscriber<Void>, CoreSubscriber<Void>, Disposable, ChannelOperationsId, Connection, DisposableChannel, HttpInfos, NettyInbound, NettyOutbound

public abstract class HttpOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound> extends ChannelOperations<INBOUND,OUTBOUND> implements HttpInfos
An HTTP ready ChannelOperations with state management for status and headers (first HTTP response packet).
Author:
Stephane Maldini
  • Constructor Details

  • Method Details

    • hasSentHeaders

      public final boolean hasSentHeaders()
      Has headers been sent.
      Returns:
      true if headers have been sent
    • isWebsocket

      public boolean isWebsocket()
      Description copied from interface: HttpInfos
      Returns true if websocket connection (upgraded).
      Specified by:
      isWebsocket in interface HttpInfos
      Returns:
      true if websocket connection
    • requestId

      public String requestId()
      Description copied from interface: HttpInfos
      Return a unique id for the request. The id is a combination of the id of the underlying connection and the serial number of the request received on that connection.

      Format of the id: <CONNECTION_ID>-<REQUEST_NUMBER>

      Example: <CONNECTION_ID>: 329c6ffd <REQUEST_NUMBER>: 5 Result: 329c6ffd-5

      Specified by:
      requestId in interface HttpInfos
      Returns:
      an unique id for the request
    • send

      public NettyOutbound send(Publisher<? extends ByteBuf> source)
      Description copied from interface: NettyOutbound
      Sends data to the peer, listens for any error on write and closes on terminal signal (complete|error).

      A new NettyOutbound type (or the same) for typed send sequences.

      Note: Nesting any send* method is not supported.

      Specified by:
      send in interface NettyOutbound
      Parameters:
      source - the dataStream publishing OUT items to write on this channel
      Returns:
      A new NettyOutbound to append further send. It will emit a complete signal successful sequence write (e.g. after "flush") or any error during write.
    • sendObject

      public NettyOutbound sendObject(Object message)
      Description copied from interface: NettyOutbound
      Sends data to the peer, listens for any error on write and closes on terminal signal (complete|error).

      Note: Nesting any send* method is not supported.

      Specified by:
      sendObject in interface NettyOutbound
      Overrides:
      sendObject in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
      Parameters:
      message - the object to publish
      Returns:
      A Mono to signal successful sequence write (e.g. after "flush") or any error during write
    • then

      public Mono<Void> then()
      Description copied from interface: NettyOutbound
      Obtains a Mono of pending outbound(s) write completion.
      Specified by:
      then in interface NettyOutbound
      Returns:
      a Mono of pending outbound(s) write completion
    • asDebugLogMessage

      protected String asDebugLogMessage(Object o)
      Description copied from class: ChannelOperations
      Transforms the object to a string for debug logs.
      Overrides:
      asDebugLogMessage in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
      Parameters:
      o - the object to be transformed
      Returns:
      the string to be logged
    • httpMessageLogFactory

      protected HttpMessageLogFactory httpMessageLogFactory()
    • beforeMarkSentHeaders

      protected abstract void beforeMarkSentHeaders()
    • afterMarkSentHeaders

      protected abstract void afterMarkSentHeaders()
    • isContentAlwaysEmpty

      protected abstract boolean isContentAlwaysEmpty()
    • onHeadersSent

      protected abstract void onHeadersSent()
    • newFullBodyMessage

      protected abstract HttpMessage newFullBodyMessage(ByteBuf body)
    • sendFile

      public final NettyOutbound sendFile(Path file, long position, long count)
      Description copied from interface: NettyOutbound
      Sends content from the given Path using FileChannel.transferTo(long, long, WritableByteChannel) support, if the system supports it, the path resolves to a local file system File, compression and SSL/TLS is not enabled, then transfer will use zero-byte copy to the peer., otherwise chunked read/write will be used.

      It will listens for any error on write and closes on terminal signal (complete|error). If more than one publisher is attached (multiple calls to send()) completion occurs after all publishers complete.

      Note: Nesting any send* method is not supported.

      Specified by:
      sendFile in interface NettyOutbound
      Parameters:
      file - the file Path
      position - where to start
      count - how much to transfer
      Returns:
      A Publisher to signal successful sequence write (e.g. after "flush") or any error during write
    • toString

      public String toString()
      Overrides:
      toString in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
    • addHandler

      public HttpOperations<INBOUND,OUTBOUND> addHandler(String name, ChannelHandler handler)
      Description copied from interface: Connection
      Add a ChannelHandler with Connection.addHandlerFirst(io.netty.channel.ChannelHandler) if of type of ChannelOutboundHandler otherwise with Connection.addHandlerLast(io.netty.channel.ChannelHandler). Implementation may add more auto handling in particular HTTP based context will prepend an HttpContent body extractor.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Specified by:
      addHandler in interface Connection
      Parameters:
      name - handler name
      handler - handler instance
      Returns:
      this Connection
    • markSentHeaders

      protected final boolean markSentHeaders(Object... objectsToRelease)
      Mark the headers sent.
      Returns:
      true if marked for the first time
    • markSentBody

      protected final boolean markSentBody()
      Mark the body sent.
      Returns:
      true if marked for the first time
    • hasSentBody

      protected final boolean hasSentBody()
      Has Body been sent.
      Returns:
      true if body has been sent
      Since:
      1.0.37
    • markSentHeaderAndBody

      protected final boolean markSentHeaderAndBody(Object... objectsToRelease)
      Mark the headers and body sent.
      Returns:
      true if marked for the first time
    • initShortId

      protected final String initShortId()
      Overrides:
      initShortId in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
    • resolvePath

      public static String resolvePath(String uri)
      Returns the decoded path portion from the provided uri.
      Parameters:
      uri - an HTTP URL that may contain a path with query/fragment
      Returns:
      the decoded path portion from the provided uri
    • outboundHttpMessage

      protected abstract HttpMessage outboundHttpMessage()
      Outbound Netty HttpMessage.
      Returns:
      Outbound Netty HttpMessage
    • prepareHttpMessage

      protected HttpMessage prepareHttpMessage(ByteBuf buffer)