Class HttpClientTools
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.tools.io.HttpClientTools
-
public class HttpClientTools extends java.lang.ObjectTools for working with HttpClient
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpClientTools.NoRedirectsStrategyA redirect strategy which does not follow any redirects.
-
Field Summary
Fields Modifier and Type Field Description static org.apache.http.client.config.RequestConfigDEFAULT_REQUEST_CONFIG
-
Constructor Summary
Constructors Constructor Description HttpClientTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertJsonContentType(org.apache.http.HttpResponse response)static voidassertSuccessWithContent(org.apache.http.HttpResponse response, java.lang.String context)static voidassertSuccessWithRedirectContent(org.apache.http.HttpResponse response, java.lang.String context)static HttpInterfaceManagercreateCookielessThreadLocalManager()static HttpInterfaceManagercreateDefaultThreadLocalManager()static org.apache.http.impl.client.HttpClientBuildercreateSharedCookiesHttpBuilder()static JsonBrowserfetchResponseAsJson(HttpInterface httpInterface, org.apache.http.client.methods.HttpUriRequest request)Executes an HTTP request and returns the response as a JsonBrowser instance.static java.lang.String[]fetchResponseLines(HttpInterface httpInterface, org.apache.http.client.methods.HttpUriRequest request, java.lang.String name)Executes an HTTP request and returns the response as an array of lines.static java.lang.StringgetHeaderValue(org.apache.http.HttpResponse response, java.lang.String name)static java.lang.StringgetRawContentType(org.apache.http.HttpResponse response)static java.lang.StringgetRedirectLocation(java.lang.String requestUrl, org.apache.http.HttpResponse response)static booleanhasJsonContentType(org.apache.http.HttpResponse response)static booleanisConnectionResetException(java.lang.Throwable exception)static booleanisRetriableNetworkException(java.lang.Throwable exception)static booleanisSuccessWithContent(int statusCode)
-
-
-
Method Detail
-
createSharedCookiesHttpBuilder
public static org.apache.http.impl.client.HttpClientBuilder createSharedCookiesHttpBuilder()
- Returns:
- An HttpClientBuilder which uses the same cookie store for all clients
-
createDefaultThreadLocalManager
public static HttpInterfaceManager createDefaultThreadLocalManager()
- Returns:
- Default HTTP interface manager with thread-local context
-
createCookielessThreadLocalManager
public static HttpInterfaceManager createCookielessThreadLocalManager()
- Returns:
- HTTP interface manager with thread-local context, ignores cookies
-
getRedirectLocation
public static java.lang.String getRedirectLocation(java.lang.String requestUrl, org.apache.http.HttpResponse response)- Parameters:
requestUrl- URL of the original request.response- Response object.- Returns:
- A redirect location if the status code indicates a redirect and the Location header is present.
-
isSuccessWithContent
public static boolean isSuccessWithContent(int statusCode)
- Parameters:
statusCode- The status code of a response.- Returns:
- True if this status code indicates a success with a response body
-
assertSuccessWithContent
public static void assertSuccessWithContent(org.apache.http.HttpResponse response, java.lang.String context) throws java.io.IOException- Parameters:
response- The response.context- Additional string to include in exception message.- Throws:
java.io.IOException- if this status code indicates an error with a response body
-
assertSuccessWithRedirectContent
public static void assertSuccessWithRedirectContent(org.apache.http.HttpResponse response, java.lang.String context) throws java.io.IOException- Parameters:
response- The response.context- Additional string to include in exception message.- Throws:
java.io.IOException- if this status code indicates an error with a response body
-
getRawContentType
public static java.lang.String getRawContentType(org.apache.http.HttpResponse response)
-
hasJsonContentType
public static boolean hasJsonContentType(org.apache.http.HttpResponse response)
-
assertJsonContentType
public static void assertJsonContentType(org.apache.http.HttpResponse response) throws java.io.IOException- Throws:
java.io.IOException
-
isRetriableNetworkException
public static boolean isRetriableNetworkException(java.lang.Throwable exception)
- Parameters:
exception- Exception to check.- Returns:
- True if retrying to connect after receiving this exception is likely to succeed.
-
isConnectionResetException
public static boolean isConnectionResetException(java.lang.Throwable exception)
-
fetchResponseAsJson
public static JsonBrowser fetchResponseAsJson(HttpInterface httpInterface, org.apache.http.client.methods.HttpUriRequest request) throws java.io.IOException
Executes an HTTP request and returns the response as a JsonBrowser instance.- Parameters:
httpInterface- HTTP interface to use for the request.request- Request to perform.- Returns:
- Response as a JsonBrowser instance. null in case of 404.
- Throws:
java.io.IOException- On network error or for non-200 response code.
-
fetchResponseLines
public static java.lang.String[] fetchResponseLines(HttpInterface httpInterface, org.apache.http.client.methods.HttpUriRequest request, java.lang.String name) throws java.io.IOException
Executes an HTTP request and returns the response as an array of lines.- Parameters:
httpInterface- HTTP interface to use for the request.request- Request to perform.name- Name of the operation to include in exception messages.- Returns:
- Array of lines from the response
- Throws:
java.io.IOException- On network error or for non-200 response code.
-
getHeaderValue
public static java.lang.String getHeaderValue(org.apache.http.HttpResponse response, java.lang.String name)- Parameters:
response- Http response to get the header value from.name- Name of the header.- Returns:
- Value if header was present, null otherwise.
-
-