// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: http.cc,v 1.44 2000/01/30 08:16:43 jgg Exp $
+// $Id: http.cc,v 1.46 2000/05/28 04:33:59 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the HTTP aquire method for APT.
It uses HTTP/1.1 and many of the fancy options there-in, such as
- pipelining, range, if-range and so on. It accepts on the command line
- a list of url destination pairs and writes to stdout the status of the
- operation as defined in the APT method spec.
-
- It is based on a doubly buffered select loop. All the requests are
+ pipelining, range, if-range and so on.
+
+ It is based on a doubly buffered select loop. A groupe of requests are
fed into a single output buffer that is constantly fed out the
socket. This provides ideal pipelining as in many cases all of the
requests will fit into a single packet. The input socket is buffered
- the same way and fed into the fd for the file.
+ the same way and fed into the fd for the file (may be a pipe in future).
This double buffering provides fairly substantial transfer rates,
compared to wget the http method is about 4% faster. Most importantly,
// ServerState::Open - Open a connection to the server /*{{{*/
// ---------------------------------------------------------------------
/* This opens a connection to the server. */
-string LastHost;
-int LastPort = 0;
-struct addrinfo *LastHostAddr = 0;
bool ServerState::Open()
{
// Use the already open connection if possible.
Close();
In.Reset();
Out.Reset();
-
+ Persistent = true;
+
// Determine the proxy setting
if (getenv("http_proxy") == 0)
{
break;
}
}
-
+
// Determine what host and port to use based on the proxy settings
int Port = 0;
string Host;
- if (Proxy.empty() == true)
+ if (Proxy.empty() == true || Proxy.Host.empty() == true)
{
if (ServerName.Port != 0)
Port = ServerName.Port;
return 2;
I = J;
}
+
+ // Tidy up the connection persistance state.
+ if (Encoding == Closes && HaveContent == true)
+ Persistent = false;
+
return 0;
}
while (Owner->Go(false,this) == true);
-
+
return 1;
}
/*}}}*/
if (sscanf(Line.c_str(),"HTTP %u %[^\n]",&Result,Code) != 2)
return _error->Error("The http server sent an invalid reply header");
}
+
+ /* Check the HTTP response header to get the default persistance
+ state. */
+ if (Major < 1)
+ Persistent = false;
+ else
+ {
+ if (Major == 1 && Minor <= 0)
+ Persistent = false;
+ else
+ Persistent = true;
+ }
return true;
}
{
HaveContent = true;
if (stringcasecmp(Val,"chunked") == 0)
- Encoding = Chunked;
-
+ Encoding = Chunked;
return true;
}
+ if (stringcasecmp(Tag,"Connection:") == 0)
+ {
+ if (stringcasecmp(Val,"close") == 0)
+ Persistent = false;
+ if (stringcasecmp(Val,"keep-alive") == 0)
+ Persistent = true;
+ return true;
+ }
+
if (stringcasecmp(Tag,"Last-Modified:") == 0)
{
if (StrToTime(Val,Date) == false)
FD_ZERO(&rfds);
FD_ZERO(&wfds);
- // Add the server
- if (Srv->Out.WriteSpace() == true && Srv->ServerFd != -1)
+ /* Add the server. We only send more requests if the connection will
+ be persisting */
+ if (Srv->Out.WriteSpace() == true && Srv->ServerFd != -1
+ && Srv->Persistent == true)
FD_SET(Srv->ServerFd,&wfds);
- if (Srv->In.ReadSpace() == true && Srv->ServerFd != -1)
+ if (Srv->In.ReadSpace() == true && Srv->ServerFd != -1)
FD_SET(Srv->ServerFd,&rfds);
// Add the file
delete Server;
Server = new ServerState(Queue->Uri,this);
}
-
+
+ /* If the server has explicitly said this is the last connection
+ then we pre-emptively shut down the pipeline and tear down
+ the connection. This will speed up HTTP/1.0 servers a tad
+ since we don't have to wait for the close sequence to
+ complete */
+ if (Server->Persistent == false)
+ Server->Close();
+
// Reset the pipeline
if (Server->ServerFd == -1)
QueueBack = Queue;
}
else
Fail(true);
-
+
break;
}