Class HttpInterface
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class HttpInterface extends java.lang.Object implements java.io.CloseableAn HTTP interface for performing HTTP requests in one specific thread. This also means it is not thread safe and should not be used in a thread it was not obtained in. For multi-thread useHttpInterfaceManager.getInterface(), should be called in each thread separately.
-
-
Constructor Summary
Constructors Constructor Description HttpInterface(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.protocol.HttpClientContext context, boolean ownedClient, HttpContextFilter filter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacquire()Acquire exclusive use of this instance.voidclose()org.apache.http.client.methods.CloseableHttpResponseexecute(org.apache.http.client.methods.HttpUriRequest request)Executes the given query using the client and context stored in this instance.org.apache.http.client.protocol.HttpClientContextgetContext()java.net.URIgetFinalLocation()org.apache.http.impl.client.CloseableHttpClientgetHttpClient()
-
-
-
Constructor Detail
-
HttpInterface
public HttpInterface(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.protocol.HttpClientContext context, boolean ownedClient, HttpContextFilter filter)- Parameters:
client- The http client instance used.context- The http context instance used.ownedClient- True if the client should be closed when this instance is closed.filter-
-
-
Method Detail
-
acquire
public boolean acquire()
Acquire exclusive use of this instance. This is released by calling close.- Returns:
- True if this instance was not exclusively used when this method was called.
-
execute
public org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpUriRequest request) throws java.io.IOExceptionExecutes the given query using the client and context stored in this instance.- Parameters:
request- The request to execute.- Returns:
- Closeable response from the server.
- Throws:
java.io.IOException- On network error.
-
getFinalLocation
public java.net.URI getFinalLocation()
- Returns:
- The final URL after redirects for the last processed request. Original URL if no redirects were performed. Null if no requests have been executed. Undefined state if last request threw an exception.
-
getContext
public org.apache.http.client.protocol.HttpClientContext getContext()
- Returns:
- Http client context used by this interface.
-
getHttpClient
public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
- Returns:
- Http client instance used by this instance.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-