Package com.mastfrog.acteur
Interface HttpEvent
- All Superinterfaces:
Event<io.netty.handler.codec.http.HttpRequest>,HttpProtocolRequest
public interface HttpEvent
extends Event<io.netty.handler.codec.http.HttpRequest>, HttpProtocolRequest
- Author:
- Tim Boudreau
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringdecodedUrlParameter(String name) default StringDeprecated.use stringContent()default <T> TgetHeader(HeaderValueType<T> value) Deprecated.use header()default StringDeprecated.use header()default <T> List<T>getHeaders(HeaderValueType<T> headerType) Deprecated.use headers()default Map<CharSequence,CharSequence> Deprecated.use headersAsMap()getIntParameter(String name) Deprecated.Use intUrlParameter()getLongParameter(String name) Deprecated.Use longUrlParameter()default com.mastfrog.acteur.util.HttpMethodDeprecated.use method()default StringgetParameter(String param) Deprecated.Use urlParameter()default <T> TgetParametersAs(Class<T> type) Deprecated.use urlParametersAsDeprecated.use urlParametersAsMap()default PathgetPath()Deprecated.use path()getRequestURL(boolean preferHeaders) Returns a best-effort at reconstructing the inbound URL, following the following algorithm: If the application has external url generation configured via PathFactory, prefer the output of that If not, try to honor non-standard but common headers such asX-Forwarded-Proto, X-URI-Scheme, Forwarded, X-Forwarded-HostApplications which respond to multiple virtual host names may need a custom implementation of PathFactory bound to do this correctly.<T> Theader(HeaderValueType<T> value) Get a header as an appropriate Java object, or null if it is not present.header(CharSequence nm) Get a single HTTP header<T> List<T>headers(HeaderValueType<T> headerType) Get all headers matching a type.Get all headers (pruning duplicate names) as a case-insensitive map of CharSequence to header value.intUrlParameter(String name) Deprecated.Uses obsolete com.google.common.base.Optionaldefault booleanDeprecated.use requestsConnectionStayOpen()default booleanbooleanisSsl()Determine if this event was over an encrypted connection.longUrlParameter(String name) Deprecated.Uses obsolete com.google.common.base.Optionalcom.mastfrog.acteur.util.HttpMethodmethod()Get the HTTP method for this requestpath()Get the logical path of this request.booleanDetermine if this request's connection header requests leaving the connection open.Get the request body as a string, in the encoding specified by the request's content-type header, or UTF-8 if none.urlParameter(String param) Get a single request parameterdefault StringurlParameter(String name, boolean decode) <T> TurlParametersAs(Class<T> type) Very primitive Java dynamic proxy magic: You write a Java interface with methods that each return a primitive type, and whose name corresponds to a URL parameter you expect to get.Gets the HTTP parameters as a flat map, ignoring duplicated keys.Methods inherited from interface com.mastfrog.acteur.Event
channel, content, ctx, getChannel, getContent, getContentAsJSON, getRemoteAddress, getRequest, jsonContent, remoteAddress, requestMethods inherited from interface com.mastfrog.acteur.request.HttpProtocolRequest
booleanUriQueryParameter, httpHeader, httpHeader, httpHeaderNames, httpMethod, isMethod, requestUri, requestUri, uriAnchor, uriAnchor, uriPathElement, uriPathElement, uriQueryParameter, uriQueryParameter, uriQueryParameter
-
Method Details
-
method
com.mastfrog.acteur.util.HttpMethod method()Get the HTTP method for this request- Returns:
- A method name
- Since:
- 2.0.0
-
header
Get a single HTTP header- Parameters:
nm- The header name- Returns:
- The header
- Since:
- 2.0.0
-
urlParameter
Get a single request parameter- Parameters:
param- The parameter name- Returns:
- A parameter or null
- Since:
- 2.0.0
-
path
Path path()Get the logical path of this request. The web application may be "mounted" on some path (i.e. it is being proxied as part of a larger site). This method will give you the path, sans the base portion of it. So, if a request URL might be forhttp://example.com/myapp/foo/bar,path()might returnfoo/bar.- Returns:
- Since:
- 2.0.0
-
header
Get a header as an appropriate Java object, or null if it is not present.- Type Parameters:
T- The return type- Parameters:
value- A header definition/parser/encoder- Returns:
- An object or null if the header is missing or invalid
- See Also:
-
a standard HTTP header types
-
headers
Get all headers matching a type.- Type Parameters:
T- The type- Parameters:
headerType- The header- Returns:
- A list of headers
- Since:
- 2.0.0
-
headersAsMap
Map<CharSequence,CharSequence> headersAsMap()Get all headers (pruning duplicate names) as a case-insensitive map of CharSequence to header value.- Returns:
- A map.
- Since:
- 2.0.0
-
urlParametersAsMap
Gets the HTTP parameters as a flat map, ignoring duplicated keys. To be technically correct, the same request parameter may be repeated any number of times, so a Map <String, List<String>> would losslessly represent parameters. In practice, this is usually a bit pedantic and annoying, so this provides a convenient way to flatten it into a map.- Returns:
- A map
- Since:
- 2.0.0
-
urlParametersAs
Very primitive Java dynamic proxy magic: You write a Java interface with methods that each return a primitive type, and whose name corresponds to a URL parameter you expect to get. Calling this method will generate a dynamic proxy object of the interface type you pass, which implements these methods to return objects, doing the necessary conversions. Be aware that conversion can result in NumberFormatExceptions, etc.- Type Parameters:
T-- Parameters:
type-- Returns:
- Since:
- 2.0.0
-
intUrlParameter
Deprecated.Uses obsolete com.google.common.base.OptionalGet a URL query string parameter as an integer.- Parameters:
name- The parameter name- Returns:
- A parameter which may not be present
- Since:
- 2.0.0
-
longUrlParameter
Deprecated.Uses obsolete com.google.common.base.OptionalGet a URL query string parameter as a long.- Parameters:
name- The parameter name- Returns:
- A long which may not be present
- Since:
- 2.0.0
-
stringContent
Get the request body as a string, in the encoding specified by the request's content-type header, or UTF-8 if none.- Returns:
- A string
- Throws:
IOException- If something goes wrong decoding the body- Since:
- 2.0.0
-
requestsConnectionStayOpen
boolean requestsConnectionStayOpen()Determine if this request's connection header requests leaving the connection open. This method is used by the framework to decide what to do at the end of sending a response. It can also be used with the settings value "neverKeepAlive" to disable any keep-alive behavior within the application. In particular, unlike Netty's utility methods, this method defaults tofalseif noConnectionheader is present.- Returns:
- True if the connection should be kept alive after the conclusion of responding to this request.
- Since:
- 2.0.0
-
isSsl
boolean isSsl()Determine if this event was over an encrypted connection.- Returns:
- True if it was encrypted
- Since:
- 2.0.0
-
getRequestURL
Returns a best-effort at reconstructing the inbound URL, following the following algorithm:- If the application has external url generation configured via PathFactory, prefer the output of that
- If not, try to honor non-standard but common headers such as
X-Forwarded-Proto, X-URI-Scheme, Forwarded, X-Forwarded-Host
- Parameters:
preferHeaders- If true, and if adequate information has been found in this request's headers, do not use PathFactory's configuration to override the result- Returns:
- A URL string
- Since:
- 2.2.2
-
isPreContent
default boolean isPreContent() -
decodedUrlParameter
-
urlParameter
-
getMethod
Deprecated.use method()Get the HTTP method for this request- Returns:
- A method name
-
getHeader
Deprecated.use header()Get a single HTTP header- Parameters:
nm- The header name- Returns:
- The header
-
getParameter
Deprecated.Use urlParameter()Get a single request parameter- Parameters:
param- The parameter name- Returns:
- A parameter or null
-
getPath
Deprecated.use path()Get the logical path of this request. The web application may be "mounted" on some path (i.e. it is being proxied as part of a larger site). This method will give you the path, sans the base portion of it. So, if a request URL might be forhttp://example.com/myapp/foo/bar,getPath()might returnfoo/bar.- Returns:
- A url path
-
getHeader
Deprecated.use header()Get a header as an appropriate Java object, or null if it is not present.- Parameters:
value- A header definition/parser/encoder- Returns:
- An object or null if the header is missing or invalid
- See Also:
-
a standard HTTP header types
-
getHeaders
Deprecated.use headers()Get all headers matching a type.- Type Parameters:
T- The type- Parameters:
headerType- The header- Returns:
- A list of headers
-
getHeadersAsMap
Deprecated.use headersAsMap()Get all headers (pruning duplicate names) as a case-insensitive map of CharSequence to header value.- Returns:
- A map.
-
getParametersAsMap
Deprecated.use urlParametersAsMap()Gets the HTTP parameters as a flat map, ignoring duplicated keys. To be technically correct, the same request parameter may be repeated any number of times, so a Map <String, List<String>> would losslessly represent parameters. In practice, this is usually a bit pedantic and annoying, so this provides a convenient way to flatten it into a map.- Returns:
- A map
-
getParametersAs
Deprecated.use urlParametersAsVery primitive Java dynamic proxy magic: You write a Java interface with methods that each return a primitive type, and whose name corresponds to a URL parameter you expect to get. Calling this method will generate a dynamic proxy object of the interface type you pass, which implements these methods to return objects, doing the necessary conversions. Be aware that conversion can result in NumberFormatExceptions, etc.- Type Parameters:
T-- Parameters:
type-- Returns:
-
getIntParameter
Deprecated.Use intUrlParameter()Get a URL query string parameter as an integer.- Parameters:
name- The parameter name- Returns:
- A parameter which may not be present
-
getLongParameter
Deprecated.Use longUrlParameter()Get a URL query string parameter as a long.- Parameters:
name- The parameter name- Returns:
- A long which may not be present
-
getContentAsString
Deprecated.use stringContent()Get the request body as a string, in the content-type header's encoding, or UTF-8 if none.- Returns:
- A string, or null if no body
- Throws:
IOException- If decoding fails
-
isKeepAlive
Deprecated.use requestsConnectionStayOpen()Determine if this request's connection header requests leaving the connection open. This method is used by the framework to decide what to do at the end of sending a response. It can also be used with the settings value "neverKeepAlive" to disable any keep-alive behavior within the application. In particular, unlike Netty's utility methods, this method defaults tofalseif noConnectionheader is present.- Returns:
- True if the connection should be kept alive after the conclusion of responding to this request.
-