summaryrefslogtreecommitdiff
path: root/methods/http.cc
diff options
context:
space:
mode:
Diffstat (limited to 'methods/http.cc')
-rw-r--r--methods/http.cc55
1 files changed, 27 insertions, 28 deletions
diff --git a/methods/http.cc b/methods/http.cc
index fddf8a78e..278ddb290 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -667,7 +667,12 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
// The HTTP server expects a hostname with a trailing :port
char Buf[1000];
- string ProperHost = Uri.Host;
+ string ProperHost;
+
+ if (Uri.Host.find(':') != string::npos)
+ ProperHost = '[' + Uri.Host + ']';
+ else
+ ProperHost = Uri.Host;
if (Uri.Port != 0)
{
sprintf(Buf,":%u",Uri.Port);
@@ -677,28 +682,27 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
// Just in case.
if (Itm->Uri.length() >= sizeof(Buf))
abort();
-
- /* Build the request. We include a keep-alive header only for non-proxy
- requests. This is to tweak old http/1.0 servers that do support keep-alive
- but not HTTP/1.1 automatic keep-alive. Doing this with a proxy server
- will glitch HTTP/1.0 proxies because they do not filter it out and
- pass it on, HTTP/1.1 says the connection should default to keep alive
- and we expect the proxy to do this */
+
+ /* RFC 2616 ยง5.1.2 requires absolute URIs for requests to proxies,
+ but while its a must for all servers to accept absolute URIs,
+ it is assumed clients will sent an absolute path for non-proxies */
+ std::string requesturi;
if (Proxy.empty() == true || Proxy.Host.empty())
- {
- // see LP bugs #1003633 and #1086997. The "+" is encoded as a workaround
- // for a amazon S3 bug
- sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
- QuoteString(Uri.Path,"+~ ").c_str(),ProperHost.c_str());
- }
+ requesturi = Uri.Path;
else
- {
- /* Generate a cache control header if necessary. We place a max
- cache age on index files, optionally set a no-cache directive
- and a no-store directive for archives. */
- sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
- Itm->Uri.c_str(),ProperHost.c_str());
- }
+ requesturi = Itm->Uri;
+
+ // The "+" is encoded as a workaround for a amazon S3 bug
+ // see LP bugs #1003633 and #1086997.
+ requesturi = QuoteString(requesturi, "+~ ");
+
+ /* Build the request. No keep-alive is included as it is the default
+ in 1.1, can cause problems with proxies, and we are an HTTP/1.1
+ client anyway.
+ C.f. https://tools.ietf.org/wg/httpbis/trac/ticket/158 */
+ sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
+ requesturi.c_str(),ProperHost.c_str());
+
// generate a cache control header (if needed)
if (_config->FindB("Acquire::http::No-Cache",false) == true)
{
@@ -975,12 +979,7 @@ HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
{
URI Uri = Queue->Uri;
if (Uri.Host.empty() == false)
- {
- if (Uri.Port != 0)
- strprintf(NextURI, "http://%s:%u", Uri.Host.c_str(), Uri.Port);
- else
- NextURI = "http://" + Uri.Host;
- }
+ NextURI = URI::SiteOnly(Uri);
else
NextURI.clear();
NextURI.append(DeQuoteString(Srv->Location));
@@ -1401,7 +1400,7 @@ bool HttpMethod::AutoDetectProxy()
char buf[512];
int InFd = Pipes[0];
close(Pipes[1]);
- int res = read(InFd, buf, sizeof(buf));
+ int res = read(InFd, buf, sizeof(buf)-1);
ExecWait(Process, "ProxyAutoDetect", true);
if (res < 0)