Package org.omegazero.http.util
Interface HTTPClient
- All Superinterfaces:
AutoCloseable,Closeable
A
HTTPClient is associated with a single connection to a server where requests can be sent to using newRequest(HTTPRequest).
The application must call receive(byte[]) when receiving data on the connection to the server.
- Since:
- 1.4.1
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Terminates thisHTTPClientat any time, causing the connection to be terminated.Returns a (possibly unmodifiable) collection of all currently active request transactions managed by thisHTTPClient.Returns the connection to the server.intReturns the maximum number of concurrent active requests thisHTTPClientcan be used for.newRequest(HTTPRequest request) Creates a newHTTPClientStreamfor the given request.voidreceive(byte[] data) Called by the application when it receives data from the server connection thisHTTPClientis associated with.default voidsetServerPushEnabled(boolean enabled) Enables or disabled server push.
-
Method Details
-
receive
Called by the application when it receives data from the server connection thisHTTPClientis associated with.- Parameters:
data- The data- Throws:
HTTPException- If the given data could not be successfully processed or is otherwise malformed
-
getConnection
WritableSocket getConnection()Returns the connection to the server.- Returns:
- The connection
-
close
void close()Terminates thisHTTPClientat any time, causing the connection to be terminated.Calling this method also closes all
.invalid reference
active requests
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
setServerPushEnabled
default void setServerPushEnabled(boolean enabled) Enables or disabled server push.If server push is not supported by the underlying protocol, this setting has no effect.
- Parameters:
enabled-trueto enable server push
-
newRequest
Creates a newHTTPClientStreamfor the given request.It is possible that this
HTTPClientcannot create a new request stream. In this case,nullis returned.- Returns:
- The
HTTPClientStream, ornullif no new request can be sent - Throws:
IllegalStateException- If thisHTTPClientis closed (optional)- See Also:
-
getActiveRequests
Collection<HTTPClientStream> getActiveRequests()Returns a (possibly unmodifiable) collection of all currently active request transactions managed by thisHTTPClient. This is the set of allHTTPClientStreams which have not received a complete response yet.- Returns:
- The collection of active
HTTPClientStreams
-
getMaxConcurrentRequestCount
int getMaxConcurrentRequestCount()Returns the maximum number of concurrent active requests thisHTTPClientcan be used for.- Returns:
- The maximum number of concurrent requests
-