content
null
for none.Implementation is not thread-safe.
private BackOffPolicy
private int
0
for an infinite timeout.private HttpContent
null
for none.private int
execute()
.private boolean
static final int
private HttpEncoding
null
for none.private HttpExecuteInterceptor
execute()
(before executing
the HTTP request) or null
for none.private boolean
true
by default).private HttpHeaders
private HttpIOExceptionHandler
null
for none.private boolean
private int
0
to not retry requests.private ObjectParser
private int
0
for an
infinite timeout.private String
null
for none.private HttpHeaders
private HttpResponseInterceptor
null
for none.private boolean
HttpResponse.getContent()
of this request should return raw input
stream or not.private boolean
private Sleeper
private boolean
USER_AGENT_SUFFIX
to the User-Agent header.private boolean
execute()
on an HTTP error code (non-2XX)
after all retries and response handlers have been exhausted (true
by default).private final io.opencensus.trace.Tracer
private final HttpTransport
private HttpUnsuccessfulResponseHandler
null
for none.private GenericUrl
static final String
private boolean
false
by default).static final String
private int
0
for an infinite timeout.private static void
addSpanAttribute(io.opencensus.trace.Span span,
String key,
String value)
execute()
Beta
executeAsync(Executor)
in a single separate
thread using Executors.newFixedThreadPool(int)
.executeAsync(Executor executor)
Beta
int
0
for an infinite
timeout.null
for none.int
execute()
.null
for none.boolean
execute()
(before executing the HTTP request) or null
for none.int
0
to not retry requests.final ObjectParser
ObjectParser
used to parse the response or null
for none.int
0
for an infinite timeout.null
for none.null
for none.boolean
HttpResponse.getContent()
should return raw input stream for this
request.boolean
setIOExceptionHandler(HttpIOExceptionHandler)
instead.boolean
USER_AGENT_SUFFIX
to the User-Agent header.boolean
execute()
on an HTTP error code
(non-2XX) after all retries and response handlers have been exhausted.null
for none.getUrl()
boolean
private static String
int
0
for an infinite timeout.boolean
handleRedirect(int statusCode,
HttpHeaders responseHeaders)
boolean
boolean
setBackOffPolicy(BackOffPolicy backOffPolicy)
setConnectTimeout(int connectTimeout)
0
for an infinite
timeout.setContent(HttpContent content)
null
for none.setContentLoggingLimit(int contentLoggingLimit)
execute()
.setCurlLoggingEnabled(boolean curlLoggingEnabled)
setEncoding(HttpEncoding encoding)
null
for none.setFollowRedirects(boolean followRedirects)
setHeaders(HttpHeaders headers)
setInterceptor(HttpExecuteInterceptor interceptor)
execute()
(before
executing the HTTP request) or null
for none.setIOExceptionHandler(HttpIOExceptionHandler ioExceptionHandler)
setLoggingEnabled(boolean loggingEnabled)
setNumberOfRetries(int numRetries)
0
to not retry requests.setParser(ObjectParser parser)
ObjectParser
used to parse the response to this request or null
for
none.setReadTimeout(int readTimeout)
0
for
an infinite timeout.setRequestMethod(String requestMethod)
null
for none.setResponseHeaders(HttpHeaders responseHeaders)
setResponseInterceptor(HttpResponseInterceptor responseInterceptor)
null
for none.setResponseReturnRawInputStream(boolean responseReturnRawInputStream)
HttpResponse.getContent()
should return raw input stream for this request.setRetryOnExecuteIOException(boolean retryOnExecuteIOException)
setIOExceptionHandler(HttpIOExceptionHandler)
instead.setSleeper(Sleeper sleeper)
setSuppressUserAgentSuffix(boolean suppressUserAgentSuffix)
USER_AGENT_SUFFIX
to the User-Agent header.setThrowExceptionOnExecuteError(boolean throwExceptionOnExecuteError)
execute()
on a HTTP error code
(non-2XX) after all retries and response handlers have been exhausted.setUnsuccessfulResponseHandler(HttpUnsuccessfulResponseHandler unsuccessfulResponseHandler)
null
for none.setUrl(GenericUrl url)
setUseRawRedirectUrls(boolean useRawRedirectUrls)
setWriteTimeout(int writeTimeout)
0
for an infinite timeout.Includes a "(gzip)"
suffix in case the server -- as Google's servers may do --
checks the User-Agent
header to try to detect if the client accepts gzip-encoded
responses.
execute()
(before executing
the HTTP request) or null
for none.For example, this can be used if you want to use a subclass of HttpHeaders
called
MyHeaders to process the response:
static String executeAndGetValueOfSomeCustomHeader(HttpRequest request) { MyHeaders responseHeaders = new MyHeaders(); request.responseHeaders = responseHeaders; HttpResponse response = request.execute(); return responseHeaders.someCustomHeader; }
0
to not retry requests. Retries occur as a result of either HttpUnsuccessfulResponseHandler
or HttpIOExceptionHandler
which handles abnormal HTTP
response or the I/O exception.execute()
.
Content will only be logged if isLoggingEnabled()
is true
.
If the content size is greater than this limit then it will not be logged.
Can be set to 0
to disable content logging. This is useful for example if content
has sensitive data such as authentication information.
Defaults to 16KB.
true
.null
for none.null
for none.0
for an infinite timeout.0
for an
infinite timeout.0
for an infinite timeout.null
for none.null
for none.null
for none.null
for none.BackOffPolicy
to use between retry attempts or null
for none.true
by default).false
by default).execute()
on an HTTP error code (non-2XX)
after all retries and response handlers have been exhausted (true
by default).IOException
is encountered in LowLevelHttpRequest.execute()
.USER_AGENT_SUFFIX
to the User-Agent header.
It is false
by default.
HttpResponse.getContent()
of this request should return raw input
stream or not.
It is false
by default.
transport
- HTTP transportrequestMethod
- HTTP request method or null
for nonenull
for none.null
for none.null
for none.null
for none.null
for none.null
for none.setUnsuccessfulResponseHandler(HttpUnsuccessfulResponseHandler)
with a new HttpBackOffUnsuccessfulResponseHandler
instead.setUnsuccessfulResponseHandler(HttpUnsuccessfulResponseHandler)
with a new HttpBackOffUnsuccessfulResponseHandler
instead.execute()
.
If the content size is greater than this limit then it will not be logged.
Content will only be logged if isLoggingEnabled()
is true
.
Can be set to 0
to disable content logging. This is useful for example if content
has sensitive data such as authentication information.
Defaults to 16KB.
execute()
.
If the content size is greater than this limit then it will not be logged.
Content will only be logged if isLoggingEnabled()
is true
.
Can be set to 0
to disable content logging. This is useful for example if content
has sensitive data such as authentication information.
Defaults to 16KB.
Defaults to true
.
Defaults to true
.
Defaults to true
.
0
for an infinite
timeout.0
for an infinite
timeout.
By default it is 20000 (20 seconds).
0
for an infinite timeout.
By default it is 20000 (20 seconds).
0
for
an infinite timeout.0
for an infinite timeout.
By default it is 0 (infinite).
0
for an infinite timeout.By default, this is a new unmodified instance of HttpHeaders
.
By default, this is a new unmodified instance of HttpHeaders
.
For example, this can be used if you want to use a subclass of HttpHeaders
called
MyHeaders to process the response:
static String executeAndGetValueOfSomeCustomHeader(HttpRequest request) { MyHeaders responseHeaders = new MyHeaders(); request.responseHeaders = responseHeaders; HttpResponse response = request.execute(); return responseHeaders.someCustomHeader; }
execute()
(before executing the HTTP request) or null
for none.execute()
(before
executing the HTTP request) or null
for none.null
for none.null
for none.null
for none.null
for none.0
to not retry requests. Retries occur as a result of either HttpUnsuccessfulResponseHandler
or HttpIOExceptionHandler
which handles abnormal HTTP
response or the I/O exception.0
to not retry requests. Retries occur as a result of either HttpUnsuccessfulResponseHandler
or HttpIOExceptionHandler
which handles abnormal HTTP
response or the I/O exception.
The default value is DEFAULT_NUMBER_OF_RETRIES
.
ObjectParser
used to parse the response to this request or null
for
none.
This parser will be preferred over any registered HttpParser.
ObjectParser
used to parse the response or null
for none.The default value is true
.
The default value is false
.
execute()
on an HTTP error code
(non-2XX) after all retries and response handlers have been exhausted.execute()
on a HTTP error code
(non-2XX) after all retries and response handlers have been exhausted.
The default value is true
.
setIOExceptionHandler(HttpIOExceptionHandler)
instead.Beta
IOException
is encountered in LowLevelHttpRequest.execute()
.setIOExceptionHandler(HttpIOExceptionHandler)
instead.Beta
IOException
is encountered in LowLevelHttpRequest.execute()
.
The default value is false
.
USER_AGENT_SUFFIX
to the User-Agent header.USER_AGENT_SUFFIX
to the User-Agent header.
The default value is false
.
HttpResponse.getContent()
should return raw input stream for this
request.HttpResponse.getContent()
should return raw input stream for this request.
The default value is false
.
Note that regardless of the returned status code, the HTTP response content has not been parsed yet, and must be parsed by the calling code.
Note that when calling to this method twice or more, the state of this HTTP request object
isn't cleared, so the request will continue where it was left. For example, the state of the
HttpUnsuccessfulResponseHandler
attached to this HTTP request will remain the same as
it was left after last execute.
Almost all details of the request and response are logged if Level.CONFIG
is
loggable. The only exception is the value of the Authorization
header which is only
logged if Level.ALL
is loggable.
Callers should call HttpResponse.disconnect()
when the returned HTTP response object
is no longer needed. However, HttpResponse.disconnect()
does not have to be called if the
response stream is properly closed. Example usage:
HttpResponse response = request.execute(); try { // process the HTTP response object } finally { response.disconnect(); }
getThrowExceptionOnExecuteError()
is false
)HttpResponseException
- for an HTTP error response (only if getThrowExceptionOnExecuteError()
is true
)IOException
Beta
executor
- executor to run the asynchronous requestBeta
executeAsync(Executor)
in a single separate
thread using Executors.newFixedThreadPool(int)
.When the status code is 303
the method on the request is changed to a GET as per the
RFC2616 specification. On a redirect, it also removes the "Authorization"
and all
"If-*"
request headers.
Upgrade warning: When handling a status code of 303, handleRedirect(int, HttpHeaders)
now correctly removes any content from the body of the new request, as GET
requests should not have content. It did not do this in prior version 1.16.
Sleeper.DEFAULT
.