diff options
author | Simo Sorce <simo@redhat.com> | 2015-04-01 14:18:08 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-04-01 20:21:43 -0400 |
commit | bb1c7cc1b597b1df1d7ff2a8b3cd37690b7a63f9 (patch) | |
tree | 39e566eaf6fdf667745cc9ffcfbc9ed892315df7 /custodia/httpd/server.py | |
parent | 13f91045b2481710763e7bf58ac542f19f349bd4 (diff) | |
download | custodia-bb1c7cc1b597b1df1d7ff2a8b3cd37690b7a63f9.tar.gz custodia-bb1c7cc1b597b1df1d7ff2a8b3cd37690b7a63f9.tar.xz custodia-bb1c7cc1b597b1df1d7ff2a8b3cd37690b7a63f9.zip |
Minor server.py fixes
Silence pylint errors due to python3 imports
Switch to HTTP 1.0 by default, this terminates each request by
default which make it handier for manual testing with clients
like curl.
Properly handle a consumer returning nothing (None) as output.
Diffstat (limited to 'custodia/httpd/server.py')
-rw-r--r-- | custodia/httpd/server.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py index 8ca7e0a..c2bed22 100644 --- a/custodia/httpd/server.py +++ b/custodia/httpd/server.py @@ -6,7 +6,7 @@ try: from SocketServer import ForkingMixIn, UnixStreamServer from urlparse import urlparse, parse_qs except ImportError: - # pylint: disable=import-error + # pylint: disable=import-error,no-name-in-module from http.server import BaseHTTPRequestHandler from socketserver import ForkingMixIn, UnixStreamServer from urllib.parse import urlparse, parse_qs @@ -145,10 +145,10 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler): The 'headers' objct must be a dictionary where keys are headers names. - By default we assume HTTP1.1, so connections may remain open. + By default we assume HTTP1.0 """ - protocol_version = "HTTP/1.1" + protocol_version = "HTTP/1.0" def __init__(self, *args, **kwargs): BaseHTTPRequestHandler.__init__(self, *args, **kwargs) @@ -157,6 +157,9 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler): self.command = '' self.raw_requestline = None self.close_connection = 0 + self.path = None + self.query = None + self.url = None def version_string(self): return self.server.server_string @@ -242,8 +245,10 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler): if hasattr(output, 'read'): shutil.copyfileobj(output, self.wfile) output.close() + elif output is not None: + self.wfile.write(str(output).encode('utf-8')) else: - self.wfile.write(output.encode('utf-8')) + self.close_connection = 1 self.wfile.flush() return except socket.timeout as e: |