20257: Need to parse status code out of the header, because pyCurl
authorPeter Amstutz <peter.amstutz@curii.com>
Wed, 19 Apr 2023 19:02:55 +0000 (15:02 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Wed, 19 Apr 2023 19:02:55 +0000 (15:02 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

sdk/python/arvados/http_import.py
sdk/python/tests/test_http.py

index d45eb7b633222aa855b6f365e94be4ce72ad6679..f4913a5b74da018deccc0d4d1a0d3e009d911e94 100644 (file)
@@ -173,7 +173,10 @@ class CurlDownloader(PyCurlHelper):
         else:
             self.name = self.parsedurl.path.split("/")[-1]
 
-        if self.curl.getinfo(pycurl.RESPONSE_CODE) == 200:
+        mt = re.match(r'^HTTP\/(\d(\.\d)?) ([1-5]\d\d) ([^\r\n\x00-\x08\x0b\x0c\x0e-\x1f\x7f]*)\r\n$', self._headers["x-status-line"])
+        code = int(mt.group(3))
+
+        if code == 200:
             self.target = self.collection.open(self.name, "wb")
 
     def body_write(self, chunk):
index 44d0d2599a9dead27f7fb1cc971a0c884dea62db..fa61e9ed8ba1a0345e85e580665c586412cca7ac 100644 (file)
@@ -59,6 +59,11 @@ class CurlMock:
     def perform(self):
         self.perform_was_called = True
 
+        if self.head:
+            self.headerfn("HTTP/1.1 {} Status".format(self.head_response))
+        else:
+            self.headerfn("HTTP/1.1 {} Status".format(self.get_response))
+
         for k,v in self.headers.items():
             self.headerfn("%s: %s" % (k,v))