From 8654fae974db3351bbb324449cf8c0f67d690bae Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 19 Jan 2012 23:51:00 +0100 Subject: * methods/https.cc: - use curls list append instead of appending Range and If-Range by hand which generates malformed requests, thanks Mel Collins for the hint! (Closes: #646381) --- methods/https.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'methods/https.cc') diff --git a/methods/https.cc b/methods/https.cc index 317c8a587..6de18b8e0 100644 --- a/methods/https.cc +++ b/methods/https.cc @@ -100,7 +100,6 @@ void HttpsMethod::SetupProxy() /*{{{*/ depth. */ bool HttpsMethod::Fetch(FetchItem *Itm) { - stringstream ss; struct stat SBuf; struct curl_slist *headers=NULL; char curl_errorstr[CURL_ERROR_SIZE]; @@ -199,6 +198,7 @@ bool HttpsMethod::Fetch(FetchItem *Itm) if (_config->FindB("Acquire::https::No-Store", _config->FindB("Acquire::http::No-Store",false)) == true) headers = curl_slist_append(headers,"Cache-Control: no-store"); + stringstream ss; ioprintf(ss, "Cache-Control: max-age=%u", _config->FindI("Acquire::https::Max-Age", _config->FindI("Acquire::http::Max-Age",0))); headers = curl_slist_append(headers, ss.str().c_str()); @@ -246,11 +246,11 @@ bool HttpsMethod::Fetch(FetchItem *Itm) if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0) { char Buf[1000]; - sprintf(Buf,"Range: bytes=%li-\r\nIf-Range: %s\r\n", - (long)SBuf.st_size - 1, - TimeRFC1123(SBuf.st_mtime).c_str()); + sprintf(Buf, "Range: bytes=%li-", (long) SBuf.st_size - 1); headers = curl_slist_append(headers, Buf); - } + sprintf(Buf, "If-Range: %s", TimeRFC1123(SBuf.st_mtime).c_str()); + headers = curl_slist_append(headers, Buf); + } else if(Itm->LastModified > 0) { curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE); -- cgit v1.2.3 From 6f4501f96f9ea256ff580129ba3835e0d56c398a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 30 Jan 2012 16:26:10 +0100 Subject: * methods/http{s,}.cc: - if a file without an extension is requested send an 'Accept: text/*' header to avoid that the server chooses unsupported compressed files in a content-negotation attempt (Closes: #657560) --- methods/https.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'methods/https.cc') diff --git a/methods/https.cc b/methods/https.cc index 6de18b8e0..4f2d581d2 100644 --- a/methods/https.cc +++ b/methods/https.cc @@ -242,6 +242,19 @@ bool HttpsMethod::Fetch(FetchItem *Itm) // error handling curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr); + // If we ask for uncompressed files servers might respond with content- + // negotation which lets us end up with compressed files we do not support, + // see 657029, 657560 and co, so if we have no extension on the request + // ask for text only. As a sidenote: If there is nothing to negotate servers + // seem to be nice and ignore it. + if (_config->FindB("Acquire::https::SendAccept", _config->FindB("Acquire::http::SendAccept", true)) == true) + { + size_t const filepos = Itm->Uri.find_last_of('/'); + string const file = Itm->Uri.substr(filepos + 1); + if (flExtension(file) == file) + headers = curl_slist_append(headers, "Accept: text/*"); + } + // if we have the file send an if-range query with a range header if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0) { -- cgit v1.2.3