cros_sdk: fix more quirks and corner cases in parsing curl HTTP responses

See section 3.1 here:

https://www.ietf.org/rfc/rfc2616.txt

that says:

"""
   The version of an HTTP message is indicated by an HTTP-Version field
   in the first line of the message.

       HTTP-Version   = "HTTP" "/" 1*DIGIT "." 1*DIGIT
"""

However, we've seen reports in the wild of (potentially non-conforming?)
HTTP/2 implementations returning 'HTTP/2 200 OK'. Rather than being
unnecessarily pedantic here, let's just accept the not-so-standard
format.

While we're at it, I noticed that the HTTP standard allows for these
major/minor revisions to roll over to 2+ digits.

And finally, note that '.' is a regex wildcard. Let's escape it
properly.

So, a few representative examples of prefixes we accept:

  'HTTP/1.0 200'
  'HTTP/1.1 200'
  'HTTP/1 200'
  'HTTP/2.0 200'
  'HTTP/2 200'
  'HTTP/99999 200'
  'HTTP/1337.987654321 200'

But we no longer allow:

  'HTTP/1a0 200'

BUG=chromium:541462
TEST=trybots; download a new checkout / build the cros_sdk chroot

Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/389815
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Dan Erat <derat@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>

Conflicts:
    scripts/cros_sdk.py - minor conflict with logging string

(cherry picked from commit cf8aef44686e40e4899a332587ca0ca0b8c58a51)
Signed-off-by: Stephen Barber <smbarber@chromium.org>

Change-Id: Ie31dda7cd09ff2b62f7590a79dc97d41ced4f307
Reviewed-on: https://chromium-review.googlesource.com/c/1410156
Reviewed-by: Brian Norris <briannorris@chromium.org>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
Tested-by: Stephen Barber <smbarber@chromium.org>
1 file changed