diff --git a/testenv/exc/server_error.py b/testenv/exc/server_error.py index dc676a85..fe359f54 100644 --- a/testenv/exc/server_error.py +++ b/testenv/exc/server_error.py @@ -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 diff --git a/testenv/server/http/http_server.py b/testenv/server/http/http_server.py index 7c0b4727..2356f1c2 100644 --- a/testenv/server/http/http_server.py +++ b/testenv/server/http/http_server.py @@ -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)