[neon/neon/livecd-rootfs/Neon/release] /: magic-proxy: fix TypeError when trying to call get_uri() LP:#1944906
Thomas Bechtold
null at kde.org
Thu Oct 28 12:37:16 BST 2021
Git commit da3c71a79142be1fc3aa73ec5644d9779a8c7321 by Thomas Bechtold.
Committed on 28/09/2021 at 11:48.
Pushed by jriddell into branch 'Neon/release'.
magic-proxy: fix TypeError when trying to call get_uri() LP:#1944906
Currently the uri that is passed into urllib.parse.urlparse() is not
prefixed with "http(s)://" which leads urlparse() to return a wrong
scheme/netloc/path. Currently it looks like:
ParseResult(scheme='', netloc='',
path='de.archive.ubuntu.com/ubuntu/dists/impish-backports/InRelease'
, params='', query='', fragment='')
That's wrong. The path should look like
'ubuntu/dists/impish-backports/InRelease'.
Prefixing the 'host' header with 'http://' in case it's not there does
fix the problem.
This fixes:
Traceback (most recent call last):
File "/usr/lib/python3.9/socketserver.py", line 683, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.9/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.9/socketserver.py", line 747, in __init__
self.handle()
File "/usr/lib/python3.9/http/server.py", line 427, in handle
self.handle_one_request()
File "/usr/lib/python3.9/http/server.py", line 415, in handle_one_request
method()
File "/home/tom/devel/livecd-rootfs/./magic-proxy", line 787, in do_GET
File "/home/tom/devel/livecd-rootfs/./magic-proxy", line 838, in __get_request
File "/home/tom/devel/livecd-rootfs/./magic-proxy", line 84, in get_uri
TypeError: can only concatenate str (not "NoneType") to str
(cherry picked from commit 3559153c7d91dfb25e6aaf1d18152e945411d503)
M +7 -1 magic-proxy
https://invent.kde.org/neon/neon/livecd-rootfs/commit/da3c71a79142be1fc3aa73ec5644d9779a8c7321
diff --git a/magic-proxy b/magic-proxy
index 29d95ab4..10f19c47 100755
--- a/magic-proxy
+++ b/magic-proxy
@@ -814,8 +814,14 @@ class ProxyingHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
It is important to understand that there is no status 3xx HTTP redirect
happening here, the client does not know that what it receives is not
exactly what it requested."""
+ host = self.headers.get("host")
+
+ # the host does not start with http(s):// which result in urlparse
+ # to not detect the host & path correctly (LP:#1944906)
+ if not host.startswith("http"):
+ host = "http://{}".format(host)
+ uri = host + self.path
- uri = self.headers.get("host") + self.path
parsed = urllib.parse.urlparse(uri)
self.sanitize_requestline()
More information about the Neon-commits
mailing list