HttpConnection
interface. On send()
, Jodd HTTP will open()
connection if not already opened. HTTP connections are created by the connection provider instance: HttpConnectionProvider
. The default connection provider is socket-based and it always returns a new SocketHttpConnection
instance - that simply wraps a Socket
and opens it.HttpConnectionProvider
, based on default implementation. For example, you may extend the SocketHttpConnectionProvider
and override createSocket()
method to return sockets from some pool, or sockets with a different timeout.HttpConnection
directly, without any provider.Socket
. Since it is a common need to tweak socket behavior before sending data, here are two ways of how you can do it with Jodd HTTP.HttpConnection
, we can simply get the instance after explicitly calling the open()
and cast it:HttpConnectionProvider
based on SocketHttpConnectionProvider
. So you may create your own provider like this:withConnectionProvider()
:open()
method:open()
method, you can not alter it via the Jodd HTTP interface. For example, setting the timeouts after the open will have no effect.HttpConnection
is opened on the first request and then re-used in communication session; the socked is not opened again if not needed and therefore it is reused for several requests.HttpConnection
(i.e. the same socket). When in 'keep-alive' mode, HTTP continues using the existing connection, while paying attention to server responses. If the server explicitly requires a connection to be closed, HTTP will close it and then it will open a new connection to continue your session. You don't have to worry about this, just keep calling keepAlive()
and it will magically do everything for you in the background. Just don't forget to pass false
argument to the last call to indicate the server that is the last connection and that we want to close after receiving the last response. (if for some reasons the server does not respond correctly, you may close communication on the client-side with an explicit call to response.close()
). One more thing - if a new connection has to be opened during this persistent session (when e.g. keep-alive max counter is finished or timeout expired) the same connection provider will be used as for the initial, first connection.HttpConnectionProvider
also allows you to specify the proxy. Just provide the ProxyInfo
instance with the information about the used proxy (type, address, port, username, password):HttpRequest
and HttpResponse
have a method readFrom(InputStream)
. Basically, you can parse the input stream with these methods. This is, for example, how you can read the request on server-side.