Class HTTPRequest (2.0.0)

public class HTTPRequest implements Serializable

HTTPRequest encapsulates a single HTTP request that is made via the URLFetchService.

Inheritance

java.lang.Object > HTTPRequest

Implements

Serializable

Constructors

HTTPRequest(URL url)

public HTTPRequest(URL url)

Creates a HTTPRequest that represents a GET request to the specified URL.

Parameter
NameDescription
urlURL

HTTPRequest(URL url, HTTPMethod method)

public HTTPRequest(URL url, HTTPMethod method)

Creates a HTTPRequest that represents an HTTP request to the specified URL with the specified HTTP method (GET, POST, etc).

Parameters
NameDescription
urlURL
methodHTTPMethod

HTTPRequest(URL url, HTTPMethod method, FetchOptions fetchOptions)

public HTTPRequest(URL url, HTTPMethod method, FetchOptions fetchOptions)

Creates a HTTPRequest that represents an HTTP request to the specified URL with the specified HTTP method (GET, POST, etc) and the specified FetchOptions.

Parameters
NameDescription
urlURL
methodHTTPMethod
fetchOptionsFetchOptions

Methods

addHeader(HTTPHeader header)

public void addHeader(HTTPHeader header)

Adds header to this request. If an HTTPHeader with the same name already exists for this request, it's values are merged with header.

Parameter
NameDescription
headerHTTPHeader

a not null HTTPHeader

getFetchOptions()

public FetchOptions getFetchOptions()

Get the fetch options for this request.

Returns
TypeDescription
FetchOptions

getHeaders()

public List<HTTPHeader> getHeaders()

Returns an immutable List of HTTPHeader objects that have been added to this request.

Returns
TypeDescription
List<HTTPHeader>

getMethod()

public HTTPMethod getMethod()

Gets the HTTP method for this request (GET, POST, etc).

Returns
TypeDescription
HTTPMethod

getPayload()

public byte @Nullable [] getPayload()

Gets the payload (such as POST body) for this request. Certain HTTP methods (e.g. GET) will not have any payload, and this method will return null.

Returns
TypeDescription
byte @org.checkerframework.checker.nullness.qual.Nullable []

getURL()

public URL getURL()

Gets the URL for this request.

Returns
TypeDescription
URL

setHeader(HTTPHeader header)

public void setHeader(HTTPHeader header)

Sets an HTTPHeader for this request. If an HTTPHeader with the same name already exists, its value is replaced.

Parameter
NameDescription
headerHTTPHeader

setPayload(byte[] payload)

public void setPayload(byte[] payload)

Sets the payload for this request. This method should not be called for certain HTTP methods (e.g. GET).

Parameter
NameDescription
payloadbyte[]