Interface HttpRequestContext
-
- All Superinterfaces:
HttpResponder,io.netty.util.ReferenceCounted
public interface HttpRequestContext extends io.netty.util.ReferenceCounted, HttpResponder
A context that runs through each HTTP requests.- Since:
- 1.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceHttpRequestContext.HttpResponseFactoryA factory to createHttpResponses.
-
Field Summary
Fields Modifier and Type Field Description static io.netty.util.AsciiStringTEXT_PLAIN_UTF8"text/plain; charset=UTF-8"
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default io.netty.buffer.ByteBufAllocatoralloc()Return the assignedByteBufAllocatorwhich will be used to allocateByteBufs.default io.netty.buffer.ByteBufbody()Returns the content body of the HTTP request.io.netty.channel.Channelchannel()Returns theChannelwhich is bound to theHttpRequestContext.<C extends HttpServerComponent>
java.util.Optional<C>component(java.lang.Class<? extends C> componentType)Returns the component with the specifiedcomponentType.intcontentLength()Returns the length of the HTTP request body content.java.util.Optional<java.lang.CharSequence>contentType()Returns the type of the HTTP request body content.default io.netty.channel.EventLoopeventLoop()Return theEventLoopthisChannelwas registered to.default booleanhasProperty(java.lang.Object key)default booleanhasProperty(java.lang.Object key, java.lang.Object value)default io.netty.handler.codec.http.HttpHeadersheaders()Returns the headers of the HTTP request.default booleanisKeepAlive()Returns if the connection iskeep-aliveor not.default io.netty.handler.codec.http.HttpMethodmethod()Returns the method of the HTTP request.default java.lang.Stringpath()Returns the decoded path string of the HTTP requestURI.PathVariablespathVariables()Returns the path variables.HttpResponderpathVariables(PathVariables pathVariables)Set the path variables.default <T> java.util.Optional<T>property(java.lang.Class<T> key)Returns the property value as parameterized type.<T> java.util.Optional<T>property(java.lang.Object key)Returns the property value as parameterized type.<T> java.util.Optional<T>property(java.lang.Object key, java.lang.Class<T> type)Returns the property value as parameterized type.HttpResponderproperty(java.lang.Object key, java.lang.Object value)Set the property value with the specified key, or remove the value with specified key by inputnullparameter.java.util.stream.Stream<java.lang.String>propertyKeyNames()Returns aStreamcontains the key name of each property in thieHttpRequestContext.default java.util.stream.Stream<java.lang.Object>propertyKeys()Deprecated.please usepropertyKeyNames()insteaddefault java.util.Optional<java.util.List<java.lang.String>>queryParameter(java.lang.String name)Returns the value of the specified name belongs to the decoded key-value parameter pairs of the HTTP requestURIdefault java.util.Map<java.lang.String,java.util.List<java.lang.String>>queryParameters()Returns the decoded key-value parameter pairs of the HTTP requestURI.io.netty.handler.codec.http.QueryStringDecoderqueryStringDecoder()Returns theQueryStringDecoderbuilt from the HTTP requestURI.default java.lang.StringrawPath()Returns the raw path of the HTTP requestURI.default java.lang.StringrawQuery()Returns the raw query string of the HTTP requestURI.default java.time.LocalDateTimereceivedLocalTime()Returns theLocalDateTimewhen the HTTP request just received.longreceivedNanoTime()Returns the value of the running Java Virtual Machine'shigh-resolution time source, in nanoseconds, when the HTTP request just received.java.time.ZonedDateTimereceivedTime()Returns theZonedDateTimewith the systemZoneIdwhen the HTTP request just received.default java.time.ZonedDateTimereceivedTime(java.time.ZoneId zone)Returns theZonedDateTimewith the specifiedZoneIdwhen the HTTP request just received.default intrefCnt()default booleanrelease()default booleanrelease(int decrement)java.lang.StringremoteAddress()Returns the remote address (client IP) of thisHttpRequestContext.io.netty.handler.codec.http.FullHttpRequestrequest()Returns theFullHttpRequestwhich is bound to theHttpRequestContext.default java.util.concurrent.CompletableFuture<HttpResult>respondBadRequestError(java.lang.Throwable cause)Send HTTP response with"400 Bad Request Error"to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>respondError(java.lang.Throwable cause)Respond HTTP error response to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>respondInternalServerError(java.lang.Throwable cause)Send HTTP response with"500 Internal Server Error"to client and returns theHttpResultasynchronously.HttpRequestContext.HttpResponseFactoryresponseFactory()Returns the factory createsHttpResponses.default HttpRequestContextretain()default HttpRequestContextretain(int increment)default java.util.concurrent.CompletableFuture<HttpResult>sendRedirect(java.lang.CharSequence location)Send HTTP response with"302 Found"to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>sendRedirect(java.lang.CharSequence location, java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)Send HTTP response with"302 Found"to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>sendResponse(io.netty.handler.codec.http.FullHttpResponse response)Send HTTP response to client and returns the HttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>sendResponse(io.netty.handler.codec.http.FullHttpResponse response, int contentLength)Send HTTP response to client and returns the HttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>simpleRespond(HttpFailureException cause)Respond a simple HTTP response with error message content to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status)Respond a simple HTTP response without content to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.buffer.ByteBuf content, int contentLength, java.lang.CharSequence contentType)Respond a simple HTTP response with the specified content to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.buffer.ByteBuf content, java.lang.CharSequence contentType)Respond a simple HTTP response with the specified content to client and returns theHttpResultasynchronously.default java.util.concurrent.CompletableFuture<HttpResult>simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status, java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)Respond a simple HTTP response without content to client and returns theHttpResultasynchronously.default HttpRequestContexttouch()default HttpRequestContexttouch(java.lang.Object hint)default io.netty.handler.codec.http.HttpHeaderstrailingHeaders()Returns the trailing headers of the HTTP request.default java.lang.Stringuri()Returns theuriof the HTTP request.default java.util.Optional<HttpServer.User>user()Returns theHttpServer.User.default <U extends HttpServer.User>
java.util.Optional<U>user(java.lang.Class<U> type)Returns theHttpServer.User.default io.netty.handler.codec.http.HttpVersionversion()Returns the protocol version of the HTTP request.
-
-
-
Method Detail
-
receivedNanoTime
long receivedNanoTime()
Returns the value of the running Java Virtual Machine'shigh-resolution time source, in nanoseconds, when the HTTP request just received.- Returns:
- the value of the running Java Virtual Machine'shigh-resolution time source, in nanoseconds
- See Also:
System.nanoTime()
-
receivedTime
java.time.ZonedDateTime receivedTime()
Returns theZonedDateTimewith the systemZoneIdwhen the HTTP request just received.- Returns:
- a
ZonedDateTime
-
receivedTime
default java.time.ZonedDateTime receivedTime(java.time.ZoneId zone)
Returns theZonedDateTimewith the specifiedZoneIdwhen the HTTP request just received.- Parameters:
zone- theZoneId- Returns:
- a
ZonedDateTimewith the specifiedzone
-
receivedLocalTime
default java.time.LocalDateTime receivedLocalTime()
Returns theLocalDateTimewhen the HTTP request just received.- Returns:
- a
LocalDateTime
-
channel
io.netty.channel.Channel channel()
Returns theChannelwhich is bound to theHttpRequestContext.- Returns:
- a
Channel
-
eventLoop
default io.netty.channel.EventLoop eventLoop()
Return theEventLoopthisChannelwas registered to.- Returns:
- a
EventLoop
-
alloc
default io.netty.buffer.ByteBufAllocator alloc()
Return the assignedByteBufAllocatorwhich will be used to allocateByteBufs.- Returns:
- a
ByteBufAllocator
-
remoteAddress
java.lang.String remoteAddress()
Returns the remote address (client IP) of thisHttpRequestContext.All implementations should fix with the HTTP PROXY header
"x-forwarded-for".- Returns:
- the remote address
-
request
io.netty.handler.codec.http.FullHttpRequest request()
Returns theFullHttpRequestwhich is bound to theHttpRequestContext.- Returns:
- a
FullHttpRequest
-
isKeepAlive
default boolean isKeepAlive()
Returns if the connection iskeep-aliveor not.- Returns:
trueif the connection iskeep-alive,falseotherwise
-
version
default io.netty.handler.codec.http.HttpVersion version()
Returns the protocol version of the HTTP request.- Returns:
- the protocol version of the HTTP request
-
method
default io.netty.handler.codec.http.HttpMethod method()
Returns the method of the HTTP request.- Returns:
- the method of the HTTP request
-
body
default io.netty.buffer.ByteBuf body()
Returns the content body of the HTTP request.- Returns:
- the content body of the HTTP request
-
contentLength
int contentLength()
Returns the length of the HTTP request body content.- Returns:
- the length of the HTTP request body content
-
headers
default io.netty.handler.codec.http.HttpHeaders headers()
Returns the headers of the HTTP request.- Returns:
- the headers of the HTTP request
-
contentType
java.util.Optional<java.lang.CharSequence> contentType()
Returns the type of the HTTP request body content.- Returns:
- the type of the HTTP request body content
-
trailingHeaders
default io.netty.handler.codec.http.HttpHeaders trailingHeaders()
Returns the trailing headers of the HTTP request.- Returns:
- the trailing headers of the HTTP request
-
queryStringDecoder
io.netty.handler.codec.http.QueryStringDecoder queryStringDecoder()
Returns theQueryStringDecoderbuilt from the HTTP requestURI.- Returns:
- a
QueryStringDecoder
-
path
default java.lang.String path()
Returns the decoded path string of the HTTP requestURI.- Returns:
- the decoded path string
-
uri
default java.lang.String uri()
Returns theuriof the HTTP request.- Returns:
- the
uristring
-
rawPath
default java.lang.String rawPath()
Returns the raw path of the HTTP requestURI.- Returns:
- the raw path string
-
rawQuery
default java.lang.String rawQuery()
Returns the raw query string of the HTTP requestURI.- Returns:
- the raw query string
-
queryParameters
default java.util.Map<java.lang.String,java.util.List<java.lang.String>> queryParameters()
Returns the decoded key-value parameter pairs of the HTTP requestURI.- Returns:
- the decoded key-value parameter pairs
-
queryParameter
default java.util.Optional<java.util.List<java.lang.String>> queryParameter(java.lang.String name)
Returns the value of the specified name belongs to the decoded key-value parameter pairs of the HTTP requestURI- Parameters:
name- the name of the query parameter- Returns:
- an
Optional<List<String>>
-
pathVariables
PathVariables pathVariables()
Returns the path variables.- Returns:
- a
PathVariables
-
pathVariables
HttpResponder pathVariables(PathVariables pathVariables)
Set the path variables.- Parameters:
pathVariables- the path variables- Returns:
- this
HttpRequestContext
-
component
<C extends HttpServerComponent> java.util.Optional<C> component(java.lang.Class<? extends C> componentType)
Returns the component with the specifiedcomponentType.- Type Parameters:
C- the type of the component- Parameters:
componentType- the type of the component- Returns:
- an
Optional<HttpServerComponent>
-
user
default java.util.Optional<HttpServer.User> user()
Returns theHttpServer.User.- Returns:
- an
Optional<T>may contains the user
-
user
default <U extends HttpServer.User> java.util.Optional<U> user(java.lang.Class<U> type) throws java.lang.ClassCastException
Returns theHttpServer.User.- Type Parameters:
U- the real type of the user- Parameters:
type- the class of the real type- Returns:
- an
Optional<U extends User>may contains the user - Throws:
java.lang.ClassCastException- if the user is notnulland is not assignable to the typeU
-
property
default <T> java.util.Optional<T> property(java.lang.Class<T> key)
Returns the property value as parameterized type.- Type Parameters:
T- the type of the property value- Parameters:
key- the key of the property, also the class of the type- Returns:
- an
Optional<T>may contains the property value
-
property
<T> java.util.Optional<T> property(java.lang.Object key) throws java.lang.ClassCastExceptionReturns the property value as parameterized type.- Type Parameters:
T- the type of the property value- Parameters:
key- the key of the property- Returns:
- an
Optional<T>may contains the property value - Throws:
java.lang.ClassCastException- if the object is notnulland is not assignable to the typeT
-
property
<T> java.util.Optional<T> property(java.lang.Object key, java.lang.Class<T> type) throws java.lang.ClassCastExceptionReturns the property value as parameterized type.- Type Parameters:
T- the type of the property value- Parameters:
key- the key of the propertytype- the class of the type- Returns:
- an
Optional<T>may contains the property value - Throws:
java.lang.ClassCastException- if the object is notnulland is not assignable to the typeT
-
property
HttpResponder property(java.lang.Object key, java.lang.Object value)
Set the property value with the specified key, or remove the value with specified key by inputnullparameter.- Parameters:
key- the key of the propertyvalue- the value of the property- Returns:
- this
HttpRequestContext
-
hasProperty
default boolean hasProperty(java.lang.Object key)
- Parameters:
key- the key of the property- Returns:
trueif thisHttpRequestContextcontains a property with the specifiedkey
-
hasProperty
default boolean hasProperty(java.lang.Object key, java.lang.Object value)- Parameters:
key- the key of the propertyvalue- the value of the property- Returns:
trueif thisHttpRequestContextcontains a property with the specifiedkeyandvalue
-
propertyKeys
@Deprecated default java.util.stream.Stream<java.lang.Object> propertyKeys()
Deprecated.please usepropertyKeyNames()insteadReturns aStreamcontains the key of each property in thisHttpRequestContext.- Returns:
- a
Stream<Object>
-
propertyKeyNames
java.util.stream.Stream<java.lang.String> propertyKeyNames()
Returns aStreamcontains the key name of each property in thieHttpRequestContext.- Returns:
- a
Stream<String> - Since:
- 1.3
-
refCnt
default int refCnt()
- Specified by:
refCntin interfaceio.netty.util.ReferenceCounted
-
retain
default HttpRequestContext retain()
- Specified by:
retainin interfaceio.netty.util.ReferenceCounted
-
retain
default HttpRequestContext retain(int increment)
- Specified by:
retainin interfaceio.netty.util.ReferenceCounted
-
touch
default HttpRequestContext touch()
- Specified by:
touchin interfaceio.netty.util.ReferenceCounted
-
touch
default HttpRequestContext touch(java.lang.Object hint)
- Specified by:
touchin interfaceio.netty.util.ReferenceCounted
-
release
default boolean release()
- Specified by:
releasein interfaceio.netty.util.ReferenceCounted
-
release
default boolean release(int decrement)
- Specified by:
releasein interfaceio.netty.util.ReferenceCounted
-
simpleRespond
default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status)
Description copied from interface:HttpResponderRespond a simple HTTP response without content to client and returns theHttpResultasynchronously.- Specified by:
simpleRespondin interfaceHttpResponder- Parameters:
status- the status- Returns:
- a
CompletableFuture<HttpResult>
-
simpleRespond
default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status, java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)
Description copied from interface:HttpResponderRespond a simple HTTP response without content to client and returns theHttpResultasynchronously.- Specified by:
simpleRespondin interfaceHttpResponder- Parameters:
status- the statusaddHeaders- a function to add headers- Returns:
- a
CompletableFuture<HttpResult>
-
respondError
default java.util.concurrent.CompletableFuture<HttpResult> respondError(java.lang.Throwable cause)
Description copied from interface:HttpResponderRespond HTTP error response to client and returns theHttpResultasynchronously.- Specified by:
respondErrorin interfaceHttpResponder- Parameters:
cause- the cause- Returns:
- a
CompletableFuture<HttpResult>
-
simpleRespond
default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond(HttpFailureException cause)
Description copied from interface:HttpResponderRespond a simple HTTP response with error message content to client and returns theHttpResultasynchronously.- Specified by:
simpleRespondin interfaceHttpResponder- Parameters:
cause- aHttpFailureException- Returns:
- a
CompletableFuture<HttpResult>
-
simpleRespond
default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.buffer.ByteBuf content, java.lang.CharSequence contentType)
Description copied from interface:HttpResponderRespond a simple HTTP response with the specified content to client and returns theHttpResultasynchronously.- Specified by:
simpleRespondin interfaceHttpResponder- Parameters:
status- the statuscontent- the contentcontentType- the type of the content- Returns:
- a
CompletableFuture<HttpResult>
-
simpleRespond
default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.buffer.ByteBuf content, int contentLength, java.lang.CharSequence contentType)
Description copied from interface:HttpResponderRespond a simple HTTP response with the specified content to client and returns theHttpResultasynchronously.- Specified by:
simpleRespondin interfaceHttpResponder- Parameters:
status- the statuscontent- the contentcontentLength- the length of the contentcontentType- the type of the content- Returns:
- a
CompletableFuture<HttpResult>
-
respondBadRequestError
default java.util.concurrent.CompletableFuture<HttpResult> respondBadRequestError(java.lang.Throwable cause)
Description copied from interface:HttpResponderSend HTTP response with"400 Bad Request Error"to client and returns theHttpResultasynchronously.- Specified by:
respondBadRequestErrorin interfaceHttpResponder- Parameters:
cause- the cause- Returns:
- a
CompletableFuture<HttpResult>
-
respondInternalServerError
default java.util.concurrent.CompletableFuture<HttpResult> respondInternalServerError(java.lang.Throwable cause)
Description copied from interface:HttpResponderSend HTTP response with"500 Internal Server Error"to client and returns theHttpResultasynchronously.- Specified by:
respondInternalServerErrorin interfaceHttpResponder- Parameters:
cause- the cause- Returns:
- a
CompletableFuture<HttpResult>
-
sendResponse
default java.util.concurrent.CompletableFuture<HttpResult> sendResponse(io.netty.handler.codec.http.FullHttpResponse response, int contentLength)
Description copied from interface:HttpResponderSend HTTP response to client and returns the HttpResultasynchronously.- Specified by:
sendResponsein interfaceHttpResponder- Parameters:
response- the FullHttpResponsecontentLength- the length of the response body content- Returns:
- a
CompletableFuture<HttpResult>
-
sendResponse
default java.util.concurrent.CompletableFuture<HttpResult> sendResponse(io.netty.handler.codec.http.FullHttpResponse response)
Description copied from interface:HttpResponderSend HTTP response to client and returns the HttpResultasynchronously.- Specified by:
sendResponsein interfaceHttpResponder- Parameters:
response- the FullHttpResponse- Returns:
- a
CompletableFuture<HttpResult>
-
sendRedirect
default java.util.concurrent.CompletableFuture<HttpResult> sendRedirect(java.lang.CharSequence location)
Description copied from interface:HttpResponderSend HTTP response with"302 Found"to client and returns theHttpResultasynchronously.- Specified by:
sendRedirectin interfaceHttpResponder- Parameters:
location- the location- Returns:
- a
CompletableFuture<HttpResult>
-
sendRedirect
default java.util.concurrent.CompletableFuture<HttpResult> sendRedirect(java.lang.CharSequence location, java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)
Description copied from interface:HttpResponderSend HTTP response with"302 Found"to client and returns theHttpResultasynchronously.- Specified by:
sendRedirectin interfaceHttpResponder- Parameters:
location- the locationaddHeaders- a function to add headers- Returns:
- a
CompletableFuture<HttpResult>
-
responseFactory
HttpRequestContext.HttpResponseFactory responseFactory()
Returns the factory createsHttpResponses.- Returns:
- the factory creates
HttpResponses
-
-