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 TypeMethodDescriptionvoid
close()
Terminates thisHTTPClient
at 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.int
Returns the maximum number of concurrent active requests thisHTTPClient
can be used for.newRequest
(HTTPRequest request) Creates a newHTTPClientStream
for the given request.void
receive
(byte[] data) Called by the application when it receives data from the server connection thisHTTPClient
is associated with.default void
setServerPushEnabled
(boolean enabled) Enables or disabled server push.
-
Method Details
-
receive
Called by the application when it receives data from the server connection thisHTTPClient
is 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 thisHTTPClient
at any time, causing the connection to be terminated.Calling this method also closes all active requests.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
-true
to enable server push
-
newRequest
Creates a newHTTPClientStream
for the given request.It is possible that this
HTTPClient
cannot create a new request stream. In this case,null
is returned.- Returns:
- The
HTTPClientStream
, ornull
if no new request can be sent - Throws:
IllegalStateException
- If thisHTTPClient
is 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 allHTTPClientStream
s which have not received a complete response yet.- Returns:
- The collection of active
HTTPClientStream
s
-
getMaxConcurrentRequestCount
int getMaxConcurrentRequestCount()Returns the maximum number of concurrent active requests thisHTTPClient
can be used for.- Returns:
- The maximum number of concurrent requests
-