cros_sdk: improve curl output parsing
Derived from CoreOS commit add4c2e24ca7e23bb3895fdea8fa58eab950f9dc
https://github.com/coreos/chromite/pull/21
"""
Blindly searching for '200 OK' doesn't work with HTTP/2 which doesn't
include a text description in the response. Match the status line by
prefix instead. Seems less foolish anyway.
"""
Might as well future-proof against HTTP revisions up to 9.9 ;)
BUG=chromium:541462, chromium:810207
TEST=`cros_sdk`; set up new chroot; trybots
Cherry picked from master. Conflicts:
* Removed call to logging
Change-Id: I5e88a4b38f357bb08449de302a5c813f572136d2
Inspired-by: Michael Marineau <michael.marineau@coreos.com>
Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/373685
Tested-by: Harry Pan <gs0622@gmail.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/957712
Reviewed-on: https://chromium-review.googlesource.com/1139699
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index 22effe1..7e39a4a 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -10,6 +10,7 @@
import glob
import os
import pwd
+import re
import signal
import sys
import time
@@ -85,6 +86,7 @@
# fail if asked to resume a complete file.
# pylint: disable=C0301,W0631
# https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3482927&group_id=976
+ status_re = re.compile(r'^HTTP/[0-9].[0-9] 200')
for url in urls:
# http://www.logilab.org/ticket/8766
# pylint: disable=E1101
@@ -101,9 +103,9 @@
print_cmd=False)
successful = False
for header in result.output.splitlines():
- # We must walk the output to find the string '200 OK' for use cases where
+ # We must walk the output to find the 200 code for use cases where
# a proxy is involved and may have pushed down the actual header.
- if header.find('200 OK') != -1:
+ if status_re.match(header):
successful = True
elif header.lower().startswith("content-length:"):
content_length = int(header.split(":", 1)[-1].strip())