X-Git-Url: https://git.hcoop.net/ntk/apt.git/blobdiff_plain/246bbb611d4cd5e2a13ecffb6cbe0e76390eae6f..92e8c1ff287ab829de825e00cdf94744e699ff97:/methods/https.cc diff --git a/methods/https.cc b/methods/https.cc index 146b2bfb..65a744e2 100644 --- a/methods/https.cc +++ b/methods/https.cc @@ -3,7 +3,7 @@ // $Id: http.cc,v 1.59 2004/05/08 19:42:35 mdz Exp $ /* ###################################################################### - HTTPS Acquire Method - This is the HTTPS aquire method for APT. + HTTPS Acquire Method - This is the HTTPS acquire method for APT. It uses libcurl @@ -18,19 +18,21 @@ #include #include #include +#include +#include +#include #include #include #include -#include #include -#include -#include #include #include +#include +#include -#include "config.h" #include "https.h" + #include /*}}}*/ using namespace std; @@ -57,6 +59,9 @@ HttpsMethod::parse_header(void *buffer, size_t size, size_t nmemb, void *userp) { me->Server->Result = 200; me->Server->StartPos = me->Server->Size; + // the actual size is not important for https as curl will deal with it + // by itself and e.g. doesn't bother us with transport-encoding… + me->Server->JunkSize = std::numeric_limits::max(); } else me->Server->StartPos = 0; @@ -74,27 +79,33 @@ size_t HttpsMethod::write_data(void *buffer, size_t size, size_t nmemb, void *userp) { HttpsMethod *me = (HttpsMethod *)userp; + size_t buffer_size = size * nmemb; + // we don't need to count the junk here, just drop anything we get as + // we don't always know how long it would be, e.g. in chunked encoding. + if (me->Server->JunkSize != 0) + return buffer_size; - if(me->File->Write(buffer, size*nmemb) != true) + if (me->Res.Size == 0) + me->URIStart(me->Res); + if(me->File->Write(buffer, buffer_size) != true) return false; - return size*nmemb; + return buffer_size; } -int -HttpsMethod::progress_callback(void *clientp, double dltotal, double dlnow, - double ultotal, double ulnow) +int +HttpsMethod::progress_callback(void *clientp, double dltotal, double /*dlnow*/, + double /*ultotal*/, double /*ulnow*/) { HttpsMethod *me = (HttpsMethod *)clientp; if(dltotal > 0 && me->Res.Size == 0) { me->Res.Size = (unsigned long long)dltotal; - me->URIStart(me->Res); } return 0; } // HttpsServerState::HttpsServerState - Constructor /*{{{*/ -HttpsServerState::HttpsServerState(URI Srv,HttpsMethod *Owner) : ServerState(Srv, NULL) +HttpsServerState::HttpsServerState(URI Srv,HttpsMethod * /*Owner*/) : ServerState(Srv, NULL) { TimeOut = _config->FindI("Acquire::https::Timeout",TimeOut); Reset(); @@ -105,6 +116,9 @@ void HttpsMethod::SetupProxy() /*{{{*/ { URI ServerName = Queue->Uri; + // Determine the proxy setting + AutoDetectProxy(ServerName); + // Curl should never read proxy settings from the environment, as // we determine which proxy to use. Do this for consistency among // methods and prevent an environment variable overriding a @@ -184,8 +198,12 @@ bool HttpsMethod::Fetch(FetchItem *Itm) curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this); + // options curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false); curl_easy_setopt(curl, CURLOPT_FILETIME, true); + // only allow curl to handle https, not the other stuff it supports + curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); + curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); // SSL parameters are set by default to the common (non mirror-specific) value // if available (or a default one) and gets overload by mirror-specific ones. @@ -304,7 +322,7 @@ bool HttpsMethod::Fetch(FetchItem *Itm) 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, + // negotiation 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. @@ -319,11 +337,11 @@ bool HttpsMethod::Fetch(FetchItem *Itm) // 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) { - char Buf[1000]; - sprintf(Buf, "Range: bytes=%li-", (long) SBuf.st_size); - headers = curl_slist_append(headers, Buf); - sprintf(Buf, "If-Range: %s", TimeRFC1123(SBuf.st_mtime).c_str()); - headers = curl_slist_append(headers, Buf); + std::string Buf; + strprintf(Buf, "Range: bytes=%lli-", (long long) SBuf.st_size); + headers = curl_slist_append(headers, Buf.c_str()); + strprintf(Buf, "If-Range: %s", TimeRFC1123(SBuf.st_mtime).c_str()); + headers = curl_slist_append(headers, Buf.c_str()); } else if(Itm->LastModified > 0) { @@ -427,7 +445,7 @@ bool HttpsMethod::Fetch(FetchItem *Itm) delete File; return true; -}; +} int main() {