Class Request
Detailed documentation available at https://www.soklet.com/docs/request-handling.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder used to construct instances ofRequest
viawith(HttpMethod, String)
.static class
-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Vends a mutable copier seeded with this instance's data, suitable for building new instances.boolean
Optional
<byte[]> getBody()
The raw bytes of the request body.Convenience method that provides thegetBody()
bytes as aString
encoded using the client-specified character set pergetCharset()
.The request's character encoding, as specified by the client in theContent-Type
header value.TheContent-Type
header 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 HTMLform
parameters 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-Language
header 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-data
fields 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 aResourcePath
representation ofgetPath()
.getUri()
The URI for this request, which must start with a/
character and might include query parameters, such as/example/123
or/one?two=three
.int
hashCode()
Was this request too large for the server to handle?Is this a request withContent-Type
ofmultipart/form-data
?toString()
static Request.Builder
with
(HttpMethod httpMethod, String uri) Acquires a builder forRequest
instances.
-
Method Details
-
with
Acquires a builder forRequest
instances.- 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/123
or/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 aResourcePath
representation ofgetPath()
.- Returns:
- the resource path for this request
-
getCookies
The cookies provided by the client for this request.The keys are the
Cookie
header names and the values areCookie
header values (it is possible for a client to send multipleCookie
headers with the same name).Note that
Cookie
headers, 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 HTMLform
parameters 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-Type
header value, as specified by the client.- Returns:
- the request's
Content-Type
header value, orOptional.empty()
if not specified
-
getCharset
The request's character encoding, as specified by the client in theContent-Type
header value.- Returns:
- the request's character encoding, or
Optional.empty()
if not specified
-
isMultipart
Is this a request withContent-Type
ofmultipart/form-data
?- Returns:
true
if this is amultipart/form-data
request,false
otherwise
-
getMultipartFields
The HTMLmultipart/form-data
fields 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 theMultipartParser
as 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:
true
if this request is larger than the server is able to handle,false
otherwise
-
getBodyAsString
Convenience method that provides thegetBody()
bytes as aString
encoded using the client-specified character set pergetCharset()
.If no character set is specified,
StandardCharsets.UTF_8
is used to perform the encoding.This method will lazily convert the raw bytes as specified by
getBody()
to an instance ofString
when first invoked. TheString
representation is then cached and re-used for subsequent invocations.This method is threadsafe.
- Returns:
- a
String
representation 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-Language
header value[s] and ordered by weight as defined by RFC 7231, Section 5.3.5.This method will lazily parse
Accept-Language
header values into to an orderedList
ofLocale
when 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
name
can support multiple values,getQueryParameters()
should be used instead of this method.If this method is invoked for a query parameter
name
with 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
name
can support multiple values,getFormParameters()
should be used instead of this method.If this method is invoked for a form parameter
name
with 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
name
can support multiple values,getHeaders()
should be used instead of this method.If this method is invoked for a header
name
with 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
name
can support multiple values,getCookies()
should be used instead of this method.If this method is invoked for a cookie
name
with multiple values, Soklet does not guarantee which value will be returned.Note that
Cookie
headers, 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
name
can support multiple multipart fields,getMultipartFields()
should be used instead of this method.If this method is invoked for a
name
with 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
-