summaryrefslogtreecommitdiffstats
path: root/custodia/httpd/server.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-04-01 18:12:06 -0400
committerSimo Sorce <simo@redhat.com>2015-04-01 20:21:43 -0400
commit2e03a2254a27159dcbdb3618b642ba78f4432494 (patch)
tree4631c571805e9ec8d2474d15de7af2dfd9004570 /custodia/httpd/server.py
parentbb1c7cc1b597b1df1d7ff2a8b3cd37690b7a63f9 (diff)
downloadcustodia-2e03a2254a27159dcbdb3618b642ba78f4432494.tar.gz
custodia-2e03a2254a27159dcbdb3618b642ba78f4432494.tar.xz
custodia-2e03a2254a27159dcbdb3618b642ba78f4432494.zip
Add code to parse body and put it in the request
Accept a maximum of 10 Megabytes and relies on proper Content-length being set by the client
Diffstat (limited to 'custodia/httpd/server.py')
-rw-r--r--custodia/httpd/server.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py
index c2bed22..0e58f0d 100644
--- a/custodia/httpd/server.py
+++ b/custodia/httpd/server.py
@@ -20,6 +20,7 @@ import sys
import traceback
SO_PEERCRED = 17
+MAX_REQUEST_SIZE = 10*1024*1024 # For now limit body to 10MiB
class HTTPError(Exception):
@@ -160,6 +161,7 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
self.path = None
self.query = None
self.url = None
+ self.body = None
def version_string(self):
return self.server.server_string
@@ -191,6 +193,15 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
return True
+ def parse_body(self):
+ length = int(self.headers.get('content-length', 0))
+ if length > MAX_REQUEST_SIZE:
+ raise HTTPError(413)
+ if length == 0:
+ self.body = None
+ else:
+ self.body = self.rfile.read(length)
+
def handle_one_request(self):
# Set a fake client address to make log functions happy
self.client_address = ['127.0.0.1', 0]
@@ -212,13 +223,20 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
if not self.parse_request():
self.close_connection = 1
return
+ try:
+ self.parse_body()
+ except HTTPError as e:
+ self.send_error(e.code, e.mesg)
+ self.wfile.flush()
+ 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}
+ 'headers': self.headers,
+ 'body': self.body}
try:
response = self.server.pipeline(request)
if response is None: