Package com.mastfrog.netty.http.client
Interface HttpRequestBuilder
public interface HttpRequestBuilder
Builds an HTTP request, allows for adding listeners for response events, and
for launching such a request.
- Author:
- Tim Boudreau
-
Method Summary
Modifier and TypeMethodDescriptionaddHeader(HeaderValueType<T> type, T value) Add a request header.addPathElement(String element) Append a path element to the URLaddQueryPair(String key, String value) Add a query key/value pair to the URLdefault HttpRequestBuilderdefault HttpRequestBuilderaddQueryPairs(Map<String, String> pairs) basicAuthentication(String username, String password) Set basic auth credentialsIf called, the request builder will not aggregate http chunks, and the full http response will not be sent to listeners.execute()Launch the requestexecute(ResponseHandler<?> response) Launch the requestDon't send the connection headerDon't create a Date: headerDon't sent the host header from the URLAdd an event handler for a particular event, using enum constants.Add an event handler for a particular eventAdd an event handler which will be called for every eventSet the anchor portion of the URLSet the request body.setCookieStore(CookieStore store) Set a cookie store which will be updated from Set-Cookie headers in the response, and which will decorate the request with any Cookies it has that match the request URL.Set the host portion of the URLsetPassword(String password) Set the password that will be put in the URL - note this is distinct from basic authentication - it results in urls such ashttp://user:password@host/pathSet the complete path of the URL (clobbering any earlier calls to add path elements)setPort(int port) Set the portsetProtocol(Protocol protocol) Set the protocol.setTimeout(Duration timeout) Set the whole URL, clobbering any earlier settingsSet the whole URL, clobbering any earlier settingssetUserName(String userName) Set the user name that will be put in the URL - note this is distinct from basic authentication - it results in urls such ashttp://user:password@host/pathtoURL()Get the URL as it currently stands for this request
-
Method Details
-
addHeader
Add a request header. TheHeadersclass implements a lot of common header types.- Type Parameters:
T- The header type- Parameters:
type- The header typevalue- The value- Returns:
- this
-
addPathElement
Append a path element to the URL- Parameters:
element- a path element- Returns:
- this
-
addQueryPair
Add a query key/value pair to the URL- Parameters:
key- A keyvalue- A value- Returns:
- this
-
addQueryPairs
-
addQueryPairs
-
setAnchor
Set the anchor portion of the URL- Parameters:
anchor- The anchor- Returns:
- this
-
setHost
Set the host portion of the URL- Parameters:
host-- Returns:
-
setPath
Set the complete path of the URL (clobbering any earlier calls to add path elements)- Parameters:
path- the path- Returns:
- this
-
setPort
Set the port- Parameters:
port- The port- Returns:
- this
-
setProtocol
Set the protocol. See the Protocols enum for common values.- Parameters:
protocol-- Returns:
-
setURL
Set the whole URL, clobbering any earlier settings- Parameters:
url-- Returns:
-
setURL
Set the whole URL, clobbering any earlier settings- Parameters:
url-- Returns:
-
setUserName
Set the user name that will be put in the URL - note this is distinct from basic authentication - it results in urls such ashttp://user:password@host/path- Parameters:
userName-- Returns:
-
setPassword
Set the password that will be put in the URL - note this is distinct from basic authentication - it results in urls such ashttp://user:password@host/path- Parameters:
userName-- Returns:
- this
-
basicAuthentication
Set basic auth credentials- Parameters:
username- The usernamepassword- The password- Returns:
- this
-
execute
Launch the request- Parameters:
response-- Returns:
-
execute
ResponseFuture execute()Launch the request- Returns:
-
setBody
Set the request body. May be a string, byte array, ByteBuf, InputStream, Image or an Object which can be converted to JSON by a vanilla ObjectMapper. For custom serialization, convert to a byte stream first.- Parameters:
o- The body- Returns:
- Throws:
IOException
-
on
Add an event handler for a particular event- Type Parameters:
T-- Parameters:
event- The event typer- The handler. If the handler is the wrong type for the object of this event, it will be called with null.- Returns:
- this
-
on
Add an event handler for a particular event, using enum constants. Use this to pick up events like connected, closed, etc. Note that it is possible to pass a Receiver for the wrong type here. In that case a warning will be logged when it is called, and you will be passed null instead. Simple events like connecting and close take Void, and will always be passed null.- Type Parameters:
T- The type of object this event produces- Parameters:
event- The type of eventr- A callback which will be called with the event contents zero or more times- Returns:
- this
-
onEvent
Add an event handler which will be called for every event- Parameters:
r- An event handler- Returns:
- this
-
toURL
URL toURL()Get the URL as it currently stands for this request- Returns:
- A url
-
noHostHeader
HttpRequestBuilder noHostHeader()Don't sent the host header from the URL- Returns:
- this
-
noConnectionHeader
HttpRequestBuilder noConnectionHeader()Don't send the connection header- Returns:
- this
-
noDateHeader
HttpRequestBuilder noDateHeader()Don't create a Date: header- Returns:
- this
-
setCookieStore
Set a cookie store which will be updated from Set-Cookie headers in the response, and which will decorate the request with any Cookies it has that match the request URL.- Parameters:
store- The cookie store- Returns:
- this
-
setTimeout
-
dontAggregateResponse
HttpRequestBuilder dontAggregateResponse()If called, the request builder will not aggregate http chunks, and the full http response will not be sent to listeners. Use this for large uploads where you intend to store the incoming chunks to disk or some other not-in-ram storage as they arrive.- Returns:
- this
-