T - the type of the implementation classpublic abstract static class H.Request<T extends H.Request> extends Object
Defines the HTTP request trait
| Modifier and Type | Field and Description |
|---|---|
protected InputStream |
inputStream |
protected Reader |
reader |
| Constructor and Description |
|---|
Request() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract Class<T> |
_impl()
Returns the class of the implementation.
|
protected abstract void |
_initCookieMap() |
protected abstract String |
_ip()
Returns remote ip address.
|
protected void |
_setCookie(String name,
H.Cookie cookie) |
H.Format |
accept()
Return the request
accept |
T |
accept(H.Format fmt)
Set
accept to the request |
T |
accept(H.MediaType mediaType) |
String |
characterEncoding()
Returns encoding of the request
|
long |
contentLength()
Returns the content length of the request
|
H.Format |
contentType()
Return content type of the request
|
<CONTEXT> CONTEXT |
context()
Get the context object from the request instance
|
T |
context(Object context)
Attach a context object to the request instance
|
abstract String |
contextPath()
Returns the context path of the request.
|
H.Cookie |
cookie(String name)
Returns cookie by it’s name
|
List<H.Cookie> |
cookies()
Returns all cookies of the request in Iterable
|
protected abstract InputStream |
createInputStream() |
static <T extends H.Request> |
current()
Return a request instance of the current execution context, For example from a
ThreadLocal |
static <T extends H.Request> |
current(T request)
Set a request instance into the current execution context, for example into a
ThreadLocal |
String |
domain()
Alias of
host(). |
String |
etag() |
boolean |
etagMatches(String etag) |
String |
fullPath()
Returns the full URI path.
|
String |
fullUrl()
Returns the full URL including scheme, domain, port and full request path plus query string
|
abstract String |
header(String name)
Returns the header content by name.
|
abstract Iterable<String> |
headers(String name)
Returns all header content by name.
|
String |
host()
Returns host of this request.
|
InputStream |
inputStream()
Returns body of the request as binary data using
InputStream |
String |
ip()
Returns the remote ip address of this request.
|
boolean |
isAjax()
Check if the request is an ajax call
|
boolean |
isModified(String etag,
long since)
Check if the requested resource is modified with etag and last timestamp (usually the timestamp of a static file e.g.)
|
Locale |
locale()
Returns locale of the request
|
org.osgl.util.C.List<Locale> |
locales()
Returns all locales of the request
|
protected T |
me() |
abstract H.Method |
method()
Returns the HTTP method of the request
|
abstract T |
method(H.Method method)
Set the Http method on this request.
|
abstract Iterable<String> |
paramNames()
Return all parameter names
|
abstract String |
paramVal(String name)
Return a request parameter value by name.
|
abstract String[] |
paramVals(String name)
Returns all values associated with the name specified in the http request.
|
String |
password()
the Http Basic password
|
abstract String |
path()
Returns the path of the request.
|
int |
port()
Returns the port of this request.
|
abstract String |
query()
Returns query string or an empty String if the request doesn’t contains a query string
|
Reader |
reader()
Returns body of the request as binary data using
Reader |
boolean |
readerCreated() |
String |
referer()
This method is an alias of
referer which follows the HTTP misspelling header name referer |
String |
referrer()
Return the “referer(sic)” header value
|
String |
scheme()
Returns the scheme of the request, specifically one of the “http” and “https”
|
abstract boolean |
secure()
Check if the request was made on a secure channel
|
String |
url()
Alias of
fullPath() |
String |
user()
The Http Basic user
|
org.osgl.web.util.UserAgent |
userAgent() |
String |
userAgentStr()
Returns useragent string of this request
|
protected volatile InputStream inputStream
protected volatile Reader reader
protected abstract Class<T> _impl()
Returns the class of the implementation. Not to be used by application
public T context(Object context)
Attach a context object to the request instance
context - the context objectpublic <CONTEXT> CONTEXT context()
Get the context object from the request instance
CONTEXT - the generic type of the context objectpublic abstract H.Method method()
Returns the HTTP method of the request
public abstract T method(H.Method method)
Set the Http method on this request. Used by framework to “override” a HTTP method
method - the method to setpublic abstract String header(String name)
Returns the header content by name. If there are multiple headers with the same name, then the first one is returned. If there is no header has the name then null is returned
Note header name is case insensitive
name - the name of the headerpublic abstract Iterable<String> headers(String name)
Returns all header content by name. This method returns content of all header with the same name specified in an Iterable of String. If there is no header has the name specified, then an empty iterable is returned.
Note header name is case insensitive
name - the name of the headerpublic T accept(H.Format fmt)
Set accept to the request
fmt - the format to be setpublic T accept(H.MediaType mediaType)
public String referrer()
Return the “referer(sic)” header value
public String referer()
This method is an alias of referer which follows the HTTP misspelling header name referer
public String etag()
public boolean etagMatches(String etag)
public boolean isAjax()
Check if the request is an ajax call
true if it is an ajax callpublic abstract String path()
Returns the path of the request. This does not include the context path. The path is a composite of HttpServletRequest.getServletPath() and HttpServletRequest.getPathInfo()
The path starts with "/" but not end with "/"
public abstract String contextPath()
Returns the context path of the request. The context path starts with “/” but not end with “/”. If there is no context path then and empty "" is returned
public String fullPath()
Returns the full URI path. It’s composed of contextPath() and path() The full path starts with “/”
public String url()
Alias of fullPath()
public String fullUrl()
Returns the full URL including scheme, domain, port and full request path plus query string
public abstract String query()
Returns query string or an empty String if the request doesn’t contains a query string
public abstract boolean secure()
Check if the request was made on a secure channel
true if this is a secure requestpublic String scheme()
Returns the scheme of the request, specifically one of the “http” and “https”
public String host()
Returns host of this request.
It will first check the X-Forwarded-Host header, if no value then check the Host header, if still no value then return empty string; otherwise
: of the value: of the valuepublic int port()
Returns the port of this request.
If port cannot be resolved, then it will return the default port: * 80 for no secure connection * 443 for secure connection
port()protected abstract String _ip()
Returns remote ip address.
public String ip()
Returns the remote ip address of this request.
The resolving process of remote ip address: 1. Check X-Forwarded-For header, if no value or value is unknown then 2. Check Proxy-Client-ip, if no value or value is unknown then 3. Check Wl-Proxy-Client-Ip, if no value or value is unknown then 4. Check HTTP_CLIENT_IP, if no value or value is unknown then 5. Check HTTP_X_FORWARDED_FOR, if no value or value is unknown then 6. return the ip address passed by underline network stack, e.g. netty or undertow
public String userAgentStr()
Returns useragent string of this request
public org.osgl.web.util.UserAgent userAgent()
protected abstract void _initCookieMap()
public H.Cookie cookie(String name)
Returns cookie by it’s name
name - the cookie namenull if not foundpublic List<H.Cookie> cookies()
Returns all cookies of the request in Iterable
public boolean isModified(String etag, long since)
Check if the requested resource is modified with etag and last timestamp (usually the timestamp of a static file e.g.)
etag - the etag to compare with “If_None_Match” header in browsersince - the last timestamp to compare with “If_Modified_Since” header in browsertrue if the resource has changed or false otherwisepublic H.Format contentType()
Return content type of the request
public String characterEncoding()
Returns encoding of the request
public Locale locale()
Returns locale of the request
public org.osgl.util.C.List<Locale> locales()
Returns all locales of the request
public long contentLength()
Returns the content length of the request
public boolean readerCreated()
protected abstract InputStream createInputStream()
public InputStream inputStream() throws IllegalStateException
Returns body of the request as binary data using InputStream
IllegalStateException - if reader() has already been called on this request instancepublic Reader reader() throws IllegalStateException
Returns body of the request as binary data using Reader
IllegalStateException - if inputStream() has already been called on this request instancepublic abstract String paramVal(String name)
Return a request parameter value by name. If there is no parameter found with the name specified, then null is returned. If there are multiple values associated with the name, then the first one is returned
name - the parameter namenull if not foundpublic abstract String[] paramVals(String name)
Returns all values associated with the name specified in the http request. If there is no parameter found with the name, then new String[0] shall be returned
name - the parameter namepublic abstract Iterable<String> paramNames()
Return all parameter names
Iterable of parameter namespublic String user()
The Http Basic user
public String password()
the Http Basic password
protected final T me()
public static <T extends H.Request> T current()
Return a request instance of the current execution context, For example from a ThreadLocal
T - the requestion typepublic static <T extends H.Request> void current(T request)
Set a request instance into the current execution context, for example into a ThreadLocal
T - the response typerequest - the request to be set to current execution contextCopyright © 2017–2018 OSGL (Open Source General Library). All rights reserved.