]> git.saurik.com Git - apt.git/blobdiff - methods/https.cc
dispose http(s) 416 error page as non-content
[apt.git] / methods / https.cc
index 0499af0c5126bc629bc0ac8b96c8a45ca98bf814..23b3a10d48f0ef3c46b7488bb7f8fcb44462bc07 100644 (file)
                                                                        /*}}}*/
 using namespace std;
 
+bool HttpsMethod::Configuration(std::string Message)
+{
+   if (pkgAcqMethod::Configuration(Message) == false)
+      return false;
+
+   DropPrivsOrDie();
+
+   return true;
+}
+
 size_t
 HttpsMethod::parse_header(void *buffer, size_t size, size_t nmemb, void *userp)
 {
@@ -59,6 +69,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<unsigned long long>::max();
       }
       else
         me->Server->StartPos = 0;
@@ -76,13 +89,25 @@ 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->Res.Size == 0)
       me->URIStart(me->Res);
-   if(me->File->Write(buffer, size*nmemb) != true)
+   if(me->File->Write(buffer, buffer_size) != true)
       return false;
 
-   return size*nmemb;
+   if(me->Queue->MaximumSize > 0 && me->File->Tell() > me->Queue->MaximumSize)
+   {
+      me->SetFailReason("MaximumSizeExceeded");
+      _error->Error("Writing more data than expected (%llu > %llu)",
+                           me->TotalWritten, me->Queue->MaximumSize);
+      return 0;
+   }
+   return buffer_size;
 }
 
 int