* @throws IOException
*/
public void send(HttpChannel httpCh)
throws IOException {
String target = httpCh.getTarget();
HttpConnection con = null;
// TODO: check ssl on connection - now if a second request
// is received on a ssl connection - we just send it
boolean ssl = httpCh.getRequest().isSecure();
HttpConnectionPool.RemoteServer remoteServer = null;
synchronized (hosts) {
remoteServer = hosts.get(target);
if (remoteServer == null) {
remoteServer = new HttpConnectionPool.RemoteServer();
remoteServer.target = target;
hosts.put(target, remoteServer);
}
}
// TODO: remove old servers and connections
// Temp magic - until a better negotiation is defined
boolean forceSpdy = "SPDY/1.0".equals(httpCh.getRequest().getProtocol());
if (forceSpdy) {
// switch back the protocol
httpCh.getRequest().setProtocol("HTTP/1.1");
}
activeRequests.incrementAndGet();
remoteServer.activeRequests.incrementAndGet();
// if we already have a spdy connection or explicitely
// requested.
if (forceSpdy || remoteServer.spdy != null) {
synchronized (remoteServer) {
if (remoteServer.spdy == null) {
remoteServer.spdy = new SpdyConnection(httpConnector,
remoteServer);
}
con = remoteServer.spdy;
}
// Will be queued - multiple threads may try to send
// at the same time, and we need to queue anyways.
con.sendRequest(httpCh);
} else {
synchronized (remoteServer) {
Http11Connection hcon;
for (int i = 0; i < remoteServer.connections.size(); i++) {
hcon = (Http11Connection) remoteServer.connections.get(i);