Support conditional GET in testenv server.

* src/exc/server_error.py: Add exception for GET to HEAD fallback.
* src/server/http/http_server.py: Do not send body if 304 return
code requested for a file.
This commit is contained in:
Hubert Tarasiuk 2015-05-11 12:34:05 +02:00 committed by Giuseppe Scrivano
parent e397a48f6a
commit 901bc98edf
2 changed files with 12 additions and 1 deletions

View File

@ -6,6 +6,12 @@ class ServerError (Exception):
def __init__(self, err_message):
self.err_message = err_message
class NoBodyServerError (Exception):
""" A custom exception which is raised by the test servers.
Used if no body should be sent in response. """
def __init__(self, err_message):
self.err_message = err_message
class AuthError (ServerError):
""" A custom exception raised byt he servers when authentication of the

View File

@ -1,5 +1,5 @@
from http.server import HTTPServer, BaseHTTPRequestHandler
from exc.server_error import ServerError, AuthError
from exc.server_error import ServerError, AuthError, NoBodyServerError
from socketserver import BaseServer
from posixpath import basename, splitext
from base64 import b64encode
@ -201,6 +201,8 @@ class _Handler(BaseHTTPRequestHandler):
def Response(self, resp_obj):
self.send_response(resp_obj.response_code)
self.finish_headers()
if resp_obj.response_code == 304:
raise NoBodyServerError("Conditional get falling to head")
raise ServerError("Custom Response code sent.")
def custom_response(self):
@ -401,6 +403,9 @@ class _Handler(BaseHTTPRequestHandler):
except AuthError as ae:
print(ae.__str__())
return(None, None)
except NoBodyServerError as nbse:
print(nbse.__str__())
return(None, None)
except ServerError as se:
print(se.__str__())
return(content, None)