public class HttpRequestImpl extends Object implements HttpRequest
An HttpRequestImpl can be modified after construction, e.g. by header(String, String).
These mutation methods return `this` for method chaining.
| Constructor and Description |
|---|
HttpRequestImpl(String method,
String uri,
HttpEntity entity)
Create an http request.
|
HttpRequestImpl(HttpRequest originRequest)
Copy an http request.
|
| Instance Methods | |
|---|---|
InetAddress |
ip()
Get the client IP.
|
boolean |
isHttps()
Whether this is an HTTPS request.
|
List<X509Certificate> |
certs()
Certificates of the client.
|
String |
method()
Get the request method.
|
String |
uri()
Get the request URI.
|
String |
uriPath()
The path component of the request URI.
|
String |
uriParam(String name)
Get the value of a parameter in the request URI.
|
String |
httpVersion()
Get the HTTP version.
|
HeaderMap |
headers()
Get the headers.
|
Map<String,String> |
cookies()
Get the request cookies.
|
HttpEntity |
entity()
Get the entity.
|
HttpRequestImpl |
ip(InetAddress ip)
Set the client IP.
|
HttpRequestImpl |
isHttps(boolean isHttps)
Set the
isHttps property.. |
HttpRequestImpl |
method(String method)
Set the request method.
|
HttpRequestImpl |
host(String host)
Set the "Host" header.
|
HttpRequestImpl |
uri(String uri)
Set the request URI.
|
HttpRequestImpl |
header(String name,
String value)
Set a header.
|
HttpRequestImpl |
cookie(String name,
String value)
Set a cookie.
|
HttpRequestImpl |
cookies(Map<String,String> cookies)
Set the cookies.
|
HttpRequestImpl |
entity(HttpEntity entity)
Set the entity.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitabsoluteUri, acceptsGzip, cookie, header, host, schemepublic HttpRequestImpl(String method, String uri, HttpEntity entity)
See uri(String) for permissible `uri` arguments.
It's preferred that `uri` is an absolute URI; otherwise,
the caller should set the host afterwards.
Examples:
new HttpRequestImpl("GET", "https://example.com/", null);
new HttpRequestImpl("GET", "/search?q=cat", null).host("localhost:8080");
new HttpRequestImpl("CONNECT", "proxy.com:8080", null);
new HttpRequestImpl("OPTIONS", "*", null).host("example.com");
public HttpRequestImpl(HttpRequest originRequest)
This can be used for request transformation, for example to change the URI, add a header, etc. The origin request is treated as read-only and will not be modified.
public InetAddress ip()
See ip(java.net.InetAddress) for changing the IP.
ip in interface HttpRequestpublic boolean isHttps()
See isHttps(boolean) for changing this property.
isHttps in interface HttpRequestHttpRequest.scheme()public List<X509Certificate> certs()
SSLSession.getPeerCertificates().certs in interface HttpRequestpublic String method()
See method(String) for changing the method.
method in interface HttpRequestpublic String uri()
See uri(String) for changing the URI.
uri in interface HttpRequestpublic String uriPath()
HttpRequest
The path is the substring before the first question mark ("?").
For example, if uri()=="/query?term=cat", then uriPath()=="/query".
uriPath in interface HttpRequestpublic String uriParam(String name)
HttpRequest
For example, if uri()=="/query?term=cat", then uriParam("term")=="cat".
The query component of the request URI is parsed as "application/x-www-form-urlencoded"
with UTF-8 charset. If there's any parsing error, this method returns null.
See FormParser for more options.
uriParam in interface HttpRequestpublic String httpVersion()
httpVersion in interface HttpRequestpublic HeaderMap headers()
The returned map is mutable; the request producer can manipulate it at will.
See also header(name,value).
headers in interface HttpRequestpublic Map<String,String> cookies()
The cookies are parsed from the "Cookie" header; see parent javadoc.
The returned Map is read-only. To modify cookies,
see cookie(String, String) and cookies(java.util.Map) methods;
or you can always set the "Cookie" header directly.
cookies in interface HttpRequestHttpRequest.cookie(String)public HttpEntity entity()
See entity(HttpEntity) for changing the entity;
entity in interface HttpRequestpublic HttpRequestImpl ip(InetAddress ip)
public HttpRequestImpl isHttps(boolean isHttps)
isHttps property..public HttpRequestImpl method(String method)
public HttpRequestImpl host(String host)
public HttpRequestImpl uri(String uri) throws IllegalArgumentException
The behavior of this method depends on the request method,
which should be settled before calling this method.
See HttpRequest.uri() for permissible `uri` arguments.
In addition, this method also accepts absolute URI,
which may change isHttps(boolean) and host(String) too.
Examples:
req.uri( "/search?q=cat" ); // path-query
req.uri( "proxy.com:8080" ); // CONNECT
req.uri( "*" ); // OPTIONS
req.uri( "https://example.com/" ); // absolute URI
IllegalArgumentExceptionpublic HttpRequestImpl header(String name, String value)
If value==null, the header will be removed.
public HttpRequestImpl cookie(String name, String value) throws IllegalArgumentException
If value==null, the cookie will be removed.
See Cookie for valid cookie name/value.
IllegalArgumentExceptionpublic HttpRequestImpl cookies(Map<String,String> cookies)
All existing cookies will be removed. This method sets a new "Cookie" header based on provided cookies.
See Cookie for valid cookie name/value.
public HttpRequestImpl entity(HttpEntity entity)