Fix a Python 3 string and mimetype issues in SCMClient.get_file_http().

Review Request #11663 — Created June 20, 2021 and submitted

Information

Review Board
release-4.0.x

Reviewers

SCMTool.get_file_http() had a couple of Python 3 incompatibility
issues, one dealing with wrong string types when adding the
Authorization header, and one dealing with access to the response
mimetype.

The authorization header was assuming Unicode strings, both when
encoding to Base64 and when adding to the header. We needed to feed a
byte string into b64encode(), then feed native strings into
add_header().

For the mimetype, we were using a legacy function to fetch the mimetype
of a response, which didn't work on Python 3. This affected querying
both Git and Mercurial over HTTP. While there are replacement functions,
it's just safer to compare the Content-Type header directly, which
this change does.

Unit tests were added to cover all the get_file_http() logic, which
will help us avoid issues in the future.

Unit tests passed on Python 2 and 3.

Tested in production with a customer who hit this issue initially.

Summary ID
Fix a Python 3 string and mimetype issues in SCMClient.get_file_http().
`SCMTool.get_file_http()` had a couple of Python 3 incompatibility issues, one dealing with wrong string types when adding the `Authorization` header, and one dealing with access to the response mimetype. The authorization header was assuming Unicode strings, both when encoding to Base64 and when adding to the header. We needed to feed a byte string into `b64encode()`, then feed native strings into `add_header()`. For the mimetype, we were using a legacy function to fetch the mimetype of a response, which didn't work on Python 3. This affected querying both Git and Mercurial over HTTP. While there are replacement functions, it's just safer to compare the `Content-Type` header directly, which this change does. Unit tests were added to cover all the `get_file_http()` logic, which will help us avoid issues in the future.
0c5da4d1d6b11f518a782f2bd548d658f1beacb2
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.0.x (f442147)
Loading...