Package io.fusionauth.http.server
Class HTTPRequest
java.lang.Object
io.fusionauth.http.server.HTTPRequest
- All Implemented Interfaces:
Buildable<HTTPRequest>
An HTTP request that is received by the HTTP server. This contains all the relevant information from the request including any file
uploads and the InputStream that the server can read from to handle the HTTP body.
This is mutable because the server is not trying to enforce that the request is always the same as the one it received. There are many cases where requests values are mutated, removed, or replaced. Rather than using a janky delegate or wrapper, this is simply mutable.
- Author:
- Brian Pontarelli
-
Constructor Summary
ConstructorsConstructorDescriptionHTTPRequest(String contextPath, int multipartBufferSize, String scheme, int port, String ipAddress) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAcceptEncoding(String encoding) voidaddAcceptEncodings(List<String> encodings) voidaddCookies(Cookie... cookies) voidaddCookies(Collection<Cookie> cookies) voidvoidaddHeaders(String name, String... values) voidaddHeaders(String name, Collection<String> values) voidaddHeaders(Map<String, List<String>> params) voidaddLocales(Collection<Locale> locales) voidaddLocales(Locale... locales) voidaddURLParameter(String name, String value) voidaddURLParameters(String name, String... values) voidaddURLParameters(String name, Collection<String> values) voidaddURLParameters(Map<String, List<String>> params) voiddeleteCookie(String name) getAttribute(String name) Retrieves a request attribute.Retrieves all the request attributes.byte[]getDateHeader(String name) getFiles()Processes the HTTP request body completely by callinggetFormData().Processes the HTTP request body completely if theContent-Typeheader is equal toHTTPValues.ContentTypes.Form.getHeaders(String name) getHost()getParameter(String name) CallsgetParameters()to combine everything and then returns the first parameter value for the given name.Combines the URL parameters and the form data that might exist in the body of the HTTP request.getParameters(String name) CallsgetParameters()to combine everything and then returns the parameters for the given name.getPath()intgetPort()intgetURLParameter(String name) getURLParameters(String name) booleanhasBody()booleanbooleanDetermines if the request is asking for the server to keep the connection alive.booleanremoveAttribute(String name) Removes a request attribute.voidremoveHeader(String name) voidremoveHeader(String name, String... values) voidsetAcceptEncodings(List<String> encodings) voidsetAttribute(String name, Object value) Sets a request attribute.voidsetCharacterEncoding(Charset encoding) voidsetContentLength(Long contentLength) voidsetContentType(String contentType) voidsetContextPath(String contextPath) voidvoidsetHeaders(String name, String... values) voidsetHeaders(String name, Collection<String> values) voidsetHeaders(Map<String, List<String>> parameters) voidvoidsetInputStream(InputStream inputStream) voidsetIPAddress(String ipAddress) voidsetMethod(HTTPMethod method) voidvoidsetPort(int port) voidsetProtocol(String protocol) voidvoidsetURLParameter(String name, String value) voidsetURLParameters(String name, String... values) voidsetURLParameters(String name, Collection<String> values) voidsetURLParameters(Map<String, List<String>> parameters)
-
Constructor Details
-
HTTPRequest
public HTTPRequest() -
HTTPRequest
-
-
Method Details
-
addAcceptEncoding
-
addAcceptEncodings
-
addCookies
-
addCookies
-
addHeader
-
addHeaders
-
addHeaders
-
addHeaders
-
addLocales
-
addLocales
-
addURLParameter
-
addURLParameters
-
addURLParameters
-
addURLParameters
-
deleteCookie
-
getAcceptEncodings
-
setAcceptEncodings
-
getAttribute
Retrieves a request attribute.- Parameters:
name- The name of the attribute.- Returns:
- The attribute or null if it doesn't exist.
-
getAttributes
Retrieves all the request attributes. This returns the direct Map so changes to the Map will affect all attributes.- Returns:
- The attribute Map.
-
getBaseURL
-
getBodyBytes
- Throws:
BodyException
-
getCharacterEncoding
-
setCharacterEncoding
-
getContentLength
-
setContentLength
-
getContentType
-
setContentType
-
getContextPath
-
setContextPath
-
getCookie
-
getCookies
-
getDateHeader
-
getFiles
Processes the HTTP request body completely by callinggetFormData(). If theContent-Typeheader is multipart, then the processing of the body will extract the files.- Returns:
- The files, if any.
-
getFormData
Processes the HTTP request body completely if theContent-Typeheader is equal toHTTPValues.ContentTypes.Form. If this method is called multiple times, the body is only processed the first time. This is not thread-safe, so you need to ensure you protect against multiple threads calling this method concurrently.If the
Content-Typeis notHTTPValues.ContentTypes.Form, this will always return an empty Map.If the InputStream is not ready or complete, this will block until all the bytes are read from the client.
- Returns:
- The Form data body.
-
getHeader
-
getHeaders
-
getHeaders
-
setHeaders
-
getHost
-
setHost
-
getIPAddress
-
setIPAddress
-
getInputStream
-
setInputStream
-
getLocale
-
getLocales
-
getMethod
-
setMethod
-
getMultipartBoundary
-
getParameter
CallsgetParameters()to combine everything and then returns the first parameter value for the given name.- Parameters:
name- The name of the parameter- Returns:
- The parameter values or null if the parameter doesn't exist.
-
getParameters
Combines the URL parameters and the form data that might exist in the body of the HTTP request. The Map returned is not linked back to the URL parameters or form data. Changing it will not impact either of those Maps. If this method is called multiple times, the merging of all the data is only done the first time and then cached. This is not thread-safe, so you need to ensure you protect against multiple threads calling this method concurrently.- Returns:
- The combined parameters.
-
getParameters
CallsgetParameters()to combine everything and then returns the parameters for the given name.- Parameters:
name- The name of the parameter- Returns:
- The parameter values or null if the parameter doesn't exist.
-
getPath
-
setPath
-
getPort
public int getPort() -
setPort
public void setPort(int port) -
getProtocol
-
setProtocol
-
getQueryString
-
getRawHost
-
getRawIPAddress
-
getRawPort
public int getRawPort() -
getRawScheme
-
getScheme
-
setScheme
-
getTransferEncoding
-
getURLParameter
-
getURLParameters
-
getURLParameters
-
setURLParameters
-
hasBody
public boolean hasBody()- Returns:
- True if the request can reasonably be assumed to have a body. This uses the fact that the request is chunked or that
Content-Lengthheader was provided.
-
isChunked
public boolean isChunked() -
isKeepAlive
public boolean isKeepAlive()Determines if the request is asking for the server to keep the connection alive. This is based on the Connection header.- Returns:
- True if the Connection header is missing or not `Close`.
-
isMultipart
public boolean isMultipart() -
removeAttribute
Removes a request attribute.- Parameters:
name- The name of the attribute.- Returns:
- The attribute if it exists.
-
removeHeader
-
removeHeader
-
setAttribute
Sets a request attribute.- Parameters:
name- The name to store the attribute under.value- The attribute value.
-
setHeader
-
setHeaders
-
setHeaders
-
setURLParameter
-
setURLParameters
-
setURLParameters
-