summaryrefslogtreecommitdiffstats
path: root/custodia/httpd/server.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-03-30 15:09:37 -0400
committerSimo Sorce <simo@redhat.com>2015-03-30 17:36:47 -0400
commit531f83b91ddfe5c811bad5b1aebfc9beb9fca1b1 (patch)
tree99bae1e9663d58e8d3dcb50efefd6adc84e5e601 /custodia/httpd/server.py
parentbf60cceb94032069bdc0a713e1f44f15a1d9670a (diff)
downloadcustodia-531f83b91ddfe5c811bad5b1aebfc9beb9fca1b1.tar.gz
custodia-531f83b91ddfe5c811bad5b1aebfc9beb9fca1b1.tar.xz
custodia-531f83b91ddfe5c811bad5b1aebfc9beb9fca1b1.zip
Provide more complete parsing of a request path
Diffstat (limited to 'custodia/httpd/server.py')
-rw-r--r--custodia/httpd/server.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py
index 9b6fbd9..8ca7e0a 100644
--- a/custodia/httpd/server.py
+++ b/custodia/httpd/server.py
@@ -4,10 +4,12 @@ try:
# pylint: disable=import-error
from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import ForkingMixIn, UnixStreamServer
+ from urlparse import urlparse, parse_qs
except ImportError:
# pylint: disable=import-error
from http.server import BaseHTTPRequestHandler
from socketserver import ForkingMixIn, UnixStreamServer
+ from urllib.parse import urlparse, parse_qs
import io
import os
import shutil
@@ -167,6 +169,25 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
pid, uid, gid = struct.unpack('3i', creds)
return {'pid': pid, 'uid': uid, 'gid': gid}
+ def parse_request(self, *args, **kwargs):
+ if not BaseHTTPRequestHandler.parse_request(self, *args, **kwargs):
+ return False
+
+ # after basic parsing also use urlparse to retrieve individual
+ # elements of a request.
+ url = urlparse(self.path)
+
+ # Yes, override path with the path part only
+ self.path = url.path
+
+ # Create dict out of query
+ self.query = parse_qs(url.query)
+
+ # keep the rest into the 'url' element in case someone needs it
+ self.url = url
+
+ return True
+
def handle_one_request(self):
# Set a fake client address to make log functions happy
self.client_address = ['127.0.0.1', 0]
@@ -186,10 +207,13 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
self.wfile.flush()
return
if not self.parse_request():
+ self.close_connection = 1
return
request = {'creds': self.peer_creds,
'command': self.command,
'path': self.path,
+ 'query': self.query,
+ 'url': self.url,
'version': self.request_version,
'headers': self.headers}
try: