Class Request
Detailed documentation available at https://www.soklet.com/docs/request-handling.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder used to construct instances ofRequestviawith(HttpMethod, String).static class -
Method Summary
Modifier and TypeMethodDescriptioncopy()Vends a mutable copier seeded with this instance's data, suitable for building new instances.booleanOptional<byte[]> getBody()The raw bytes of the request body.Convenience method that provides thegetBody()bytes as aStringencoded using the client-specified character set pergetCharset().The request's character encoding, as specified by the client in theContent-Typeheader value.TheContent-Typeheader value, as specified by the client.Convenience method to access a cookie's value when at most one is expected for the givenname.The cookies provided by the client for this request.getCors()Non-preflight CORS request data.CORS preflight-related request data.getFormParameter(String name) Convenience method to access a form parameter's value when at most one is expected for the givenname.The HTMLformparameters provided by the client for this request.Convenience method to access a header's value when at most one is expected for the givenname.The headers provided by the client for this request.The HTTP method for this request.getId()An application-specific identifier for this request.Locale information for this request as specified byAccept-Languageheader value[s] and ordered by weight as defined by RFC 7231, Section 5.3.5.getMultipartField(String name) Convenience method to access a multipart field when at most one is expected for the givenname.The HTMLmultipart/form-datafields provided by the client for this request.getPath()The path component of this request, which is a representation of the value returned bygetUri()with the query string (if any) removed.getQueryParameter(String name) Convenience method to access a query parameter's value when at most one is expected for the givenname.The query parameters provided by the client for this request.Convenience method to acquire aResourcePathrepresentation ofgetPath().getUri()The URI for this request, which must start with a/character and might include query parameters, such as/example/123or/one?two=three.inthashCode()Was this request too large for the server to handle?Is this a request withContent-Typeofmultipart/form-data?toString()static Request.Builderwith(HttpMethod httpMethod, String uri) Acquires a builder forRequestinstances.
-
Method Details
-
with
Acquires a builder forRequestinstances.- Parameters:
httpMethod- the HTTP method for this request (GET, POST, etc.)uri- the URI for this request, which must start with a/character and might include query parameters, e.g./example/123or/one?two=three- Returns:
- the builder
-
copy
Vends a mutable copier seeded with this instance's data, suitable for building new instances.- Returns:
- a copier for this instance
-
toString
-
equals
-
hashCode
-
getId
-
getHttpMethod
The HTTP method for this request.- Returns:
- the request's HTTP method
-
getUri
-
getPath
-
getResourcePath
Convenience method to acquire aResourcePathrepresentation ofgetPath().- Returns:
- the resource path for this request
-
getCookies
The cookies provided by the client for this request.The keys are the
Cookieheader names and the values areCookieheader values (it is possible for a client to send multipleCookieheaders with the same name).Note that
Cookieheaders, like all request headers, have case-insensitive names per the HTTP spec.Use
getCookie(String)for a convenience method to access cookie values when only one is expected.- Returns:
- the request's cookies
-
getQueryParameters
The query parameters provided by the client for this request.The keys are the query parameter names and the values are query parameter values (it is possible for a client to send multiple query parameters with the same name, e.g.
?test=1&test=2).Note that query parameters have case-sensitive names per the HTTP spec.
Use
getQueryParameter(String)for a convenience method to access query parameter values when only one is expected.- Returns:
- the request's query parameters
-
getFormParameters
The HTMLformparameters provided by the client for this request.The keys are the form parameter names and the values are form parameter values (it is possible for a client to send multiple form parameters with the same name, e.g.
?test=1&test=2).Note that form parameters have case-sensitive names per the HTTP spec.
Use
getFormParameter(String)for a convenience method to access form parameter values when only one is expected.- Returns:
- the request's form parameters
-
getHeaders
The headers provided by the client for this request.The keys are the header names and the values are header values (it is possible for a client to send multiple headers with the same name).
Note that request headers have case-insensitive names per the HTTP spec.
Use
getHeader(String)for a convenience method to access header values when only one is expected.- Returns:
- the request's headers
-
getContentType
TheContent-Typeheader value, as specified by the client.- Returns:
- the request's
Content-Typeheader value, orOptional.empty()if not specified
-
getCharset
The request's character encoding, as specified by the client in theContent-Typeheader value.- Returns:
- the request's character encoding, or
Optional.empty()if not specified
-
isMultipart
Is this a request withContent-Typeofmultipart/form-data?- Returns:
trueif this is amultipart/form-datarequest,falseotherwise
-
getMultipartFields
The HTMLmultipart/form-datafields provided by the client for this request.The keys are the multipart field names and the values are multipart field values (it is possible for a client to send multiple multipart fields with the same name).
Note that multipart fields have case-sensitive names per the HTTP spec.
Use
getMultipartField(String)for a convenience method to access a multipart parameter field value when only one is expected.When using
DefaultServer, multipart fields are parsed using theMultipartParseras configured byDefaultServer.Builder.multipartParser(MultipartParser).- Returns:
- the request's multipart fields, or the empty map if none are present
-
getBody
The raw bytes of the request body.For convenience,
getBodyAsString()is available if you expect your request body to be of typeString.- Returns:
- the request body bytes, or
Optional.empty()if none was supplied
-
isContentTooLarge
Was this request too large for the server to handle?If so, this request might have incomplete sets of headers/cookies. It will always have a zero-length body.
Soklet is designed to power systems that exchange small "transactional" payloads that live entirely in memory. It is not appropriate for handling multipart files at scale, buffering uploads to disk, streaming, etc.
When using
DefaultServer, maximum request size is configured byDefaultServer.Builder.maximumRequestSizeInBytes(Integer).- Returns:
trueif this request is larger than the server is able to handle,falseotherwise
-
getBodyAsString
Convenience method that provides thegetBody()bytes as aStringencoded using the client-specified character set pergetCharset().If no character set is specified,
StandardCharsets.UTF_8is used to perform the encoding.This method will lazily convert the raw bytes as specified by
getBody()to an instance ofStringwhen first invoked. TheStringrepresentation is then cached and re-used for subsequent invocations.This method is threadsafe.
- Returns:
- a
Stringrepresentation of this request's body, orOptional.empty()if no request body was specified by the client
-
getCors
Non-preflight CORS request data.See https://www.soklet.com/docs/cors for details.
- Returns:
- non-preflight CORS request data, or
Optional.empty()if none was specified
-
getCorsPreflight
CORS preflight-related request data.See https://www.soklet.com/docs/cors for details.
- Returns:
- preflight CORS request data, or
Optional.empty()if none was specified
-
getLocales
Locale information for this request as specified byAccept-Languageheader value[s] and ordered by weight as defined by RFC 7231, Section 5.3.5.This method will lazily parse
Accept-Languageheader values into to an orderedListofLocalewhen first invoked. This representation is then cached and re-used for subsequent invocations.This method is threadsafe.
- Returns:
- locale information for this request, or the empty list if none was specified
-
getQueryParameter
Convenience method to access a query parameter's value when at most one is expected for the givenname.If a query parameter
namecan support multiple values,getQueryParameters()should be used instead of this method.If this method is invoked for a query parameter
namewith multiple values, Soklet does not guarantee which value will be returned.Note that query parameters have case-sensitive names per the HTTP spec.
- Parameters:
name- the name of the query parameter- Returns:
- the value for the query parameter, or
Optional.empty()if none is present
-
getFormParameter
Convenience method to access a form parameter's value when at most one is expected for the givenname.If a form parameter
namecan support multiple values,getFormParameters()should be used instead of this method.If this method is invoked for a form parameter
namewith multiple values, Soklet does not guarantee which value will be returned.Note that form parameters have case-sensitive names per the HTTP spec.
- Parameters:
name- the name of the form parameter- Returns:
- the value for the form parameter, or
Optional.empty()if none is present
-
getHeader
Convenience method to access a header's value when at most one is expected for the givenname.If a header
namecan support multiple values,getHeaders()should be used instead of this method.If this method is invoked for a header
namewith multiple values, Soklet does not guarantee which value will be returned.Note that request headers have case-insensitive names per the HTTP spec.
- Parameters:
name- the name of the header- Returns:
- the value for the header, or
Optional.empty()if none is present
-
getCookie
Convenience method to access a cookie's value when at most one is expected for the givenname.If a cookie
namecan support multiple values,getCookies()should be used instead of this method.If this method is invoked for a cookie
namewith multiple values, Soklet does not guarantee which value will be returned.Note that
Cookieheaders, like all request headers, have case-insensitive names per the HTTP spec.- Parameters:
name- the name of the cookie- Returns:
- the value for the cookie, or
Optional.empty()if none is present
-
getMultipartField
Convenience method to access a multipart field when at most one is expected for the givenname.If a
namecan support multiple multipart fields,getMultipartFields()should be used instead of this method.If this method is invoked for a
namewith multiple multipart field values, Soklet does not guarantee which value will be returned.Note that multipart fields have case-sensitive names per the HTTP spec.
- Parameters:
name- the name of the multipart field- Returns:
- the multipart field value, or
Optional.empty()if none is present
-