Package com.azure.core.http
Class HttpRequest
- java.lang.Object
-
- com.azure.core.http.HttpRequest
-
public class HttpRequest extends Object
The outgoing Http request. It provides ways to constructHttpRequest
withHttpMethod
,URL
,HttpHeader
and request body.
-
-
Constructor Summary
Constructors Constructor Description HttpRequest(HttpMethod httpMethod, String url)
Create a new HttpRequest instance.HttpRequest(HttpMethod httpMethod, URL url)
Create a new HttpRequest instance.HttpRequest(HttpMethod httpMethod, URL url, HttpHeaders headers, Flux<ByteBuffer> body)
Create a new HttpRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequest
copy()
Creates a copy of the request.Flux<ByteBuffer>
getBody()
Get the request content.HttpHeaders
getHeaders()
Get the request headers.HttpMethod
getHttpMethod()
Get the request method.URL
getUrl()
Get the target address.HttpRequest
setBody(byte[] content)
Set the request content.HttpRequest
setBody(String content)
Set the request content.HttpRequest
setBody(Flux<ByteBuffer> content)
Set request content.HttpRequest
setHeader(String name, String value)
Set a request header, replacing any existing value.HttpRequest
setHeaders(HttpHeaders headers)
Set the request headers.HttpRequest
setHttpMethod(HttpMethod httpMethod)
Set the request method.HttpRequest
setUrl(String url)
Set the target address to send the request to.HttpRequest
setUrl(URL url)
Set the target address to send the request to.
-
-
-
Constructor Detail
-
HttpRequest
public HttpRequest(HttpMethod httpMethod, URL url)
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request to
-
HttpRequest
public HttpRequest(HttpMethod httpMethod, String url)
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request to- Throws:
IllegalArgumentException
- ifurl
is null or it cannot be parsed into a valid URL.
-
HttpRequest
public HttpRequest(HttpMethod httpMethod, URL url, HttpHeaders headers, Flux<ByteBuffer> body)
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request toheaders
- the HTTP headers to use with this requestbody
- the request content
-
-
Method Detail
-
getHttpMethod
public HttpMethod getHttpMethod()
Get the request method.- Returns:
- the request method
-
setHttpMethod
public HttpRequest setHttpMethod(HttpMethod httpMethod)
Set the request method.- Parameters:
httpMethod
- the request method- Returns:
- this HttpRequest
-
getUrl
public URL getUrl()
Get the target address.- Returns:
- the target address
-
setUrl
public HttpRequest setUrl(URL url)
Set the target address to send the request to.- Parameters:
url
- target address asURL
- Returns:
- this HttpRequest
-
setUrl
public HttpRequest setUrl(String url)
Set the target address to send the request to.- Parameters:
url
- target address as a String- Returns:
- this HttpRequest
- Throws:
IllegalArgumentException
- ifurl
is null or it cannot be parsed into a valid URL.
-
getHeaders
public HttpHeaders getHeaders()
Get the request headers.- Returns:
- headers to be sent
-
setHeaders
public HttpRequest setHeaders(HttpHeaders headers)
Set the request headers.- Parameters:
headers
- the set of headers- Returns:
- this HttpRequest
-
setHeader
public HttpRequest setHeader(String name, String value)
Set a request header, replacing any existing value. A null forvalue
will remove the header if one with matching name exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
- this HttpRequest
-
getBody
public Flux<ByteBuffer> getBody()
Get the request content.- Returns:
- the content to be send
-
setBody
public HttpRequest setBody(String content)
Set the request content.The Content-Length header will be set based on the given content's length.
- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
setBody
public HttpRequest setBody(byte[] content)
Set the request content.The Content-Length header will be set based on the given content's length.
- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
setBody
public HttpRequest setBody(Flux<ByteBuffer> content)
Set request content.Caller must set the Content-Length header to indicate the length of the content, or use Transfer-Encoding: chunked.
- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
copy
public HttpRequest copy()
Creates a copy of the request. The main purpose of this is so that this HttpRequest can be changed and the resulting HttpRequest can be a backup. This means that the cloned HttpHeaders and body must not be able to change from side effects of this HttpRequest.- Returns:
- a new HTTP request instance with cloned instances of all mutable properties.
-
-