public abstract class HttpOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound> extends ChannelOperations<INBOUND,OUTBOUND> implements HttpInfos
ChannelOperations
with state management for status and headers
(first HTTP response packet).Modifier and Type | Class and Description |
---|---|
protected static class |
HttpOperations.PostHeadersNettyOutbound |
ChannelOperations.OnSetup
Disposable.Composite, Disposable.Swap
Modifier | Constructor and Description |
---|---|
protected |
HttpOperations(Connection connection,
ConnectionObserver listener,
HttpMessageLogFactory httpMessageLogFactory) |
protected |
HttpOperations(HttpOperations<INBOUND,OUTBOUND> replaced) |
Modifier and Type | Method and Description |
---|---|
HttpOperations<INBOUND,OUTBOUND> |
addHandler(String name,
ChannelHandler handler)
Add a
ChannelHandler with Connection.addHandlerFirst(io.netty.channel.ChannelHandler) if of type of
ChannelOutboundHandler otherwise with
Connection.addHandlerLast(io.netty.channel.ChannelHandler) . |
protected abstract void |
afterMarkSentHeaders() |
protected String |
asDebugLogMessage(Object o)
Transforms the object to a string for debug logs.
|
protected abstract void |
beforeMarkSentHeaders() |
protected boolean |
hasSentBody()
Has Body been sent.
|
boolean |
hasSentHeaders()
Has headers been sent.
|
protected HttpMessageLogFactory |
httpMessageLogFactory() |
protected String |
initShortId() |
protected abstract boolean |
isContentAlwaysEmpty() |
boolean |
isWebsocket()
Returns true if websocket connection (upgraded).
|
protected boolean |
markSentBody()
Mark the body sent.
|
protected boolean |
markSentHeaderAndBody(Object... objectsToRelease)
Mark the headers and body sent.
|
protected boolean |
markSentHeaders(Object... objectsToRelease)
Mark the headers sent.
|
protected abstract HttpMessage |
newFullBodyMessage(ByteBuf body) |
protected abstract void |
onHeadersSent() |
protected abstract HttpMessage |
outboundHttpMessage()
Outbound Netty HttpMessage.
|
protected HttpMessage |
prepareHttpMessage(ByteBuf buffer) |
String |
requestId()
Return a unique id for the request.
|
static String |
resolvePath(String uri)
Returns the decoded path portion from the provided
uri . |
NettyOutbound |
send(Publisher<? extends ByteBuf> source)
Sends data to the peer, listens for any error on write and closes on terminal signal
(complete|error).
|
NettyOutbound |
sendFile(Path file,
long position,
long count)
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. |
NettyOutbound |
sendObject(Object message)
Sends data to the peer, listens for any error on write and closes on terminal signal
(complete|error).
|
Mono<Void> |
then()
Obtains a
Mono of pending outbound(s) write completion. |
String |
toString() |
addMetricsHandler, addReactiveBridge, afterInboundComplete, alloc, as, asLongText, asShortText, channel, connection, currentContext, discard, discardWhenNoReceiver, dispose, disposeSubscriber, formatName, get, inbound, isDisposed, isInboundCancelled, isInboundComplete, isInboundDisposed, isPersistent, isSubscriptionDisposed, listener, onComplete, onDispose, onDispose, onError, onInboundCancel, onInboundClose, onInboundComplete, onInboundError, onInboundNext, onNext, onOutboundComplete, onOutboundError, onSubscribe, onTerminate, onUnprocessedOutboundError, onWritabilityChanged, outbound, receive, receiveObject, send, sendObject, sendUsing, terminate, withConnection, wrapInboundError
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
cookies, fullPath, isKeepAlive, method, path, uri, version
neverComplete, sendByteArray, sendFile, sendFileChunked, sendGroups, sendObject, sendString, sendString, subscribe, then, then
addHandler, addHandlerFirst, addHandlerFirst, addHandlerLast, addHandlerLast, bind, from, markPersistent, onReadIdle, onWriteIdle, rebind, removeHandler, replaceHandler
address, disposeNow, disposeNow
protected HttpOperations(HttpOperations<INBOUND,OUTBOUND> replaced)
protected HttpOperations(Connection connection, ConnectionObserver listener, HttpMessageLogFactory httpMessageLogFactory)
public final boolean hasSentHeaders()
public boolean isWebsocket()
HttpInfos
isWebsocket
in interface HttpInfos
public String requestId()
HttpInfos
Format of the id:
<CONNECTION_ID>-<REQUEST_NUMBER>
Example:
<CONNECTION_ID>: 329c6ffd
<REQUEST_NUMBER>: 5
Result: 329c6ffd-5
public NettyOutbound send(Publisher<? extends ByteBuf> source)
NettyOutbound
A new NettyOutbound
type (or the same) for typed send
sequences.
Note: Nesting any send* method is not supported.
send
in interface NettyOutbound
source
- the dataStream publishing OUT items to write on this channelNettyOutbound
to append further send. It will emit a complete
signal successful sequence write (e.g. after "flush") or any error during write.public NettyOutbound sendObject(Object message)
NettyOutbound
Note: Nesting any send* method is not supported.
sendObject
in interface NettyOutbound
sendObject
in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
message
- the object to publishMono
to signal successful sequence write (e.g. after "flush") or
any error during writepublic Mono<Void> then()
NettyOutbound
Mono
of pending outbound(s) write completion.then
in interface NettyOutbound
Mono
of pending outbound(s) write completionprotected String asDebugLogMessage(Object o)
ChannelOperations
asDebugLogMessage
in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
o
- the object to be transformedprotected HttpMessageLogFactory httpMessageLogFactory()
protected abstract void beforeMarkSentHeaders()
protected abstract void afterMarkSentHeaders()
protected abstract boolean isContentAlwaysEmpty()
protected abstract void onHeadersSent()
protected abstract HttpMessage newFullBodyMessage(ByteBuf body)
public final NettyOutbound sendFile(Path file, long position, long count)
NettyOutbound
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.
sendFile
in interface NettyOutbound
file
- the file Pathposition
- where to startcount
- how much to transferpublic String toString()
toString
in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
public HttpOperations<INBOUND,OUTBOUND> addHandler(String name, ChannelHandler handler)
Connection
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.)
addHandler
in interface Connection
name
- handler namehandler
- handler instanceprotected final boolean markSentHeaders(Object... objectsToRelease)
protected final boolean markSentBody()
protected final boolean hasSentBody()
protected final boolean markSentHeaderAndBody(Object... objectsToRelease)
protected final String initShortId()
initShortId
in class ChannelOperations<INBOUND extends NettyInbound,OUTBOUND extends NettyOutbound>
public static String resolvePath(String uri)
uri
.uri
- an HTTP URL that may contain a path with query/fragmenturi
protected abstract HttpMessage outboundHttpMessage()
protected HttpMessage prepareHttpMessage(ByteBuf buffer)