summaryrefslogtreecommitdiff
path: root/swift/common/bufferedhttp.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2019-03-12 13:36:21 -0700
committerTim Burke <tim.burke@gmail.com>2019-09-20 21:14:40 -0700
commit53a6386791e3237e2a95db3a1a86a046b11e0664 (patch)
tree08b1d22b940bc9685fd6195af1fab60a2f6e49ab /swift/common/bufferedhttp.py
parent23ab47e023af7350aa37c5701b62b4d61f3d07ec (diff)
downloadswift-stable/ocata.tar.gz
Fix stable gateocata-eolstable/ocata
This is a combination of 2 commits. --- py2/3: Stop using stdlib's putrequest(); it only does ASCII Note that this only affects the functest client. See also: https://bugs.python.org/issue36274 and https://bugs.python.org/issue38216 This was previously done just for py3 compatibility, but following https://github.com/python/cpython/commit/bb8071a our stable gates are all broken -- apparently, they're running a 2.7 pre-release? (cherry picked from commit c0ae48ba9aafb0b91869ea3bae8da07a32088777) (cherry picked from commit 2b4d58952cae8b174fb60529d5284c1d328e9287) --- bufferedhttp: ensure query params are properly quoted Recent versions of py27 [1] have begun raising InvalidURL if you try to include non-ASCII characters in the request path. This was observed recently in the periodic checks of stable/ocata and stable/pike. In particular, we would spin up some in-process servers in test.unit.proxy.test_server.TestSocketObjectVersions and do a container listing with a prefix param that included raw (unquoted) UTF-8. This query string would pass unmolested through the proxy, tripping the InvalidURL error when bufferedhttp called putrequest. More recent versions of Swift would not exhibit this particular failure, as the listing_formats middleware would force a decoding/re-encoding of the query string for account and container requests. However, object requests with errant query strings would likely be able to trip the same error. Swift on py3 should not exhibit this behavior, as we so thoroughly re-write the request line to avoid hitting https://bugs.python.org/issue33973. Now, always parse and re-encode the query string in bufferedhttp. This prevents any errors on object requests and cleans up any callers that might use bufferedhttp directly. [1] Anything after https://github.com/python/cpython/commit/bb8071a; see https://bugs.python.org/issue30458 Closes-Bug: 1843816 Related-Change: Id3ce37aa0402e2d8dd5784ce329d7cb4fbaf700d Related-Change: Ie648f5c04d4415f3b620fb196fa567ce7575d522 (cherry picked from commit 49f62f6ab7fd1b833e9b5bfbcaafa4b45b592d34) (cherry picked from commit 9cc6d4138946034516fdf579ac084cb954ea6b06) --- Change-Id: I4eafc5f057df8a3c15560ace255d05602db56ef6
Diffstat (limited to 'swift/common/bufferedhttp.py')
-rw-r--r--swift/common/bufferedhttp.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/swift/common/bufferedhttp.py b/swift/common/bufferedhttp.py
index 129460913..ecf9b155e 100644
--- a/swift/common/bufferedhttp.py
+++ b/swift/common/bufferedhttp.py
@@ -35,7 +35,7 @@ import socket
import eventlet
from eventlet.green.httplib import CONTINUE, HTTPConnection, HTTPMessage, \
HTTPResponse, HTTPSConnection, _UNKNOWN
-from six.moves.urllib.parse import quote
+from six.moves.urllib.parse import quote, parse_qsl, urlencode
import six
if six.PY2:
@@ -240,6 +240,15 @@ def http_connect_raw(ipaddr, port, method, path, headers=None,
else:
conn = BufferedHTTPConnection('%s:%s' % (ipaddr, port))
if query_string:
+ # Round trip to ensure proper quoting
+ if six.PY2:
+ query_string = urlencode(parse_qsl(
+ query_string, keep_blank_values=True))
+ else:
+ query_string = urlencode(
+ parse_qsl(query_string, keep_blank_values=True,
+ encoding='latin1'),
+ encoding='latin1')
path += '?' + query_string
conn.path = path
conn.putrequest(method, path, skip_host=(headers and 'Host' in headers))