public class HttpClientConnection extends Object implements TimedConnection
Modifier and Type | Class and Description |
---|---|
private class |
HttpClientConnection.OutboundRequestImpl
HTTP-based implementation of OutboundRequest abstraction.
|
Modifier and Type | Field and Description |
---|---|
private String[] |
acks |
private static int |
BUSY |
private static String |
clientString |
private static int |
CLOSED |
private static int |
DIRECT |
private static int |
HTTP_MAJOR |
private static int |
HTTP_MINOR |
private static int |
IDLE |
private InputStream |
in |
private HttpClientManager |
manager |
private int |
mode |
private OutputStream |
out |
private boolean |
persist |
private static int |
PROXIED |
private ServerInfo |
proxyInfo |
private Socket |
sock |
private int |
state |
private Object |
stateLock |
private ServerInfo |
targetInfo |
private static int |
TUNNELED |
Constructor and Description |
---|
HttpClientConnection(String host,
int port,
HttpClientSocketFactory factory,
HttpClientManager manager)
Creates HttpClientConnection which sends requests directly to given
host/port through a socket obtained from the given socket factory.
|
HttpClientConnection(String targetHost,
int targetPort,
String proxyHost,
int proxyPort,
boolean tunnel,
boolean persist,
HttpClientSocketFactory factory,
HttpClientManager manager)
Creates HttpClientConnection which sends requests to given target
host/port through the indicated HTTP proxy over a socket provided by the
specified socket factory.
|
Modifier and Type | Method and Description |
---|---|
private void |
analyzePostResponse(StartLine inLine,
Header inHeader)
Analyzes POST response message start line and header, updating cached
target/proxy server information if necessary.
|
private void |
analyzeProxyResponse(StartLine inLine,
Header inHeader)
Analyzes CONNECT or OPTIONS response message start line and header sent
by proxy, updating proxy server information if necessary.
|
private void |
connect(HttpClientSocketFactory factory)
Opens underlying connection.
|
private Header |
createBaseHeader()
Creates base header containing fields common to all HTTP messages sent
by this connection.
|
private Header |
createConnectHeader()
Creates header for use in CONNECT messages sent to proxies.
|
private Header |
createOptionsHeader()
Creates header for use in OPTIONS messages sent to proxies.
|
private Header |
createPostHeader(StartLine sline)
Creates header for outbound HTTP POST message with given start line.
|
private StartLine |
createPostLine()
Creates start line for outbound HTTP POST message.
|
private void |
disconnect()
Closes and releases reference to underlying socket.
|
private void |
fetchServerInfo()
Fetches latest server/proxy HTTP information from cache.
|
private void |
flushServerInfo()
Flushes current copy of server/proxy HTTP information to cache.
|
Socket |
getSocket()
Returns socket over which requests are sent.
|
protected void |
idle()
Upcall indicating that connection has become idle.
|
private void |
markBusy()
Marks connection busy.
|
private void |
markIdle()
Marks connection idle.
|
OutboundRequest |
newRequest()
Initiates new request to connection target.
|
boolean |
ping()
Pings target.
|
private boolean |
ping(boolean setup)
Pings target.
|
private boolean |
requestProxyConnect()
Sends CONNECT request to proxy.
|
private boolean |
requestProxyOptions()
Sends OPTIONS request to proxy.
|
private void |
setupConnection(HttpClientSocketFactory factory)
Establishes connection using sockets from the given socket factory.
|
boolean |
shutdown(boolean force)
Attempts to shut down connection, returning true if connection is
closed.
|
private boolean |
supportsChunking()
Returns true if requests sent over this connection should chunk output.
|
private boolean |
supportsPersist(StartLine sline,
Header header)
Returns true if the given response line and header indicate that the
connection can be persisted, and use of persistent connections has
not been disabled.
|
private static final int HTTP_MAJOR
private static final int HTTP_MINOR
private static final String clientString
private static final int DIRECT
private static final int PROXIED
private static final int TUNNELED
private static final int IDLE
private static final int BUSY
private static final int CLOSED
private final int mode
private final Object stateLock
private int state
private final HttpClientManager manager
private ServerInfo targetInfo
private ServerInfo proxyInfo
private final boolean persist
private String[] acks
private Socket sock
private OutputStream out
private InputStream in
public HttpClientConnection(String host, int port, HttpClientSocketFactory factory, HttpClientManager manager) throws IOException
IOException
public HttpClientConnection(String targetHost, int targetPort, String proxyHost, int proxyPort, boolean tunnel, boolean persist, HttpClientSocketFactory factory, HttpClientManager manager) throws IOException
IOException
public boolean ping() throws IOException
IOException
public OutboundRequest newRequest() throws IOException
IOException
protected void idle()
public Socket getSocket()
public boolean shutdown(boolean force)
shutdown
in interface TimedConnection
private void fetchServerInfo()
private void flushServerInfo()
private void markBusy() throws IOException
IOException
private void markIdle()
private void setupConnection(HttpClientSocketFactory factory) throws IOException
IOException
private void connect(HttpClientSocketFactory factory) throws IOException
IOException
private void disconnect()
private boolean ping(boolean setup) throws IOException
IOException
private boolean requestProxyOptions() throws IOException
IOException
private boolean requestProxyConnect() throws IOException
IOException
private StartLine createPostLine()
private Header createBaseHeader()
private Header createConnectHeader()
private Header createOptionsHeader()
private Header createPostHeader(StartLine sline)
private void analyzePostResponse(StartLine inLine, Header inHeader)
private void analyzeProxyResponse(StartLine inLine, Header inHeader)
private boolean supportsChunking()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.