diff options
author | Mariusz Wagner <mariusz.wagner@nokia.com> | 2019-04-11 12:17:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-11 12:17:58 +0000 |
commit | 774e37d70f6e21df3de0172679b744ebd26f16be (patch) | |
tree | 09bf855e54d59fa8fe27d8144ca29c222cccd6fa /tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py | |
parent | 3afc3edd05021de2a5b9f8cfa379a5249700092d (diff) | |
parent | 0de17cccb4a235cd467496df7a7a4ca29c81f97d (diff) |
Merge "PRH simulators refactor"
Diffstat (limited to 'tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py')
-rw-r--r-- | tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py b/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py index 7b54539a..e91927e3 100644 --- a/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py +++ b/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py @@ -2,32 +2,44 @@ import _thread import ssl from http.server import HTTPServer - -def header_200_and_json(self): +def set_response_200_ok(self, payload = None): self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() + if payload != None: + self.wfile.write(payload) + +def set_response_404_not_found(self): + self.send_response(404) + self.end_headers() + +def set_response_500_server_error(self): + self.send_response(500) + self.end_headers() +def get_payload(self): + if self.headers['Content-Length'] == None: + raise Exception('Invalid payload, Content-Length not defined') + + content_length = int(self.headers['Content-Length']) + return self.rfile.read(content_length) def start_http_endpoint(port, handler_class): _thread.start_new_thread(init_http_endpoints, (port, handler_class)) - def start_https_endpoint(port, handler_class, keyfile, certfile, ca_certs): _thread.start_new_thread(init_https_endpoints, (port, handler_class, keyfile, certfile, ca_certs)) - def init_http_endpoints(port, handler_class, server_class=HTTPServer): server = server_class(('', port), handler_class) sa = server.socket.getsockname() print("Serving HTTP on", sa[0], "port", sa[1], "for", handler_class, "...") server.serve_forever() - def init_https_endpoints(port, handler_class, keyfile, certfile, ca_certs, server_class=HTTPServer): server = server_class(('', port), handler_class) server.socket = ssl.wrap_socket(server.socket, keyfile=keyfile, certfile=certfile, ca_certs=ca_certs, server_side=True) sa = server.socket.getsockname() print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...") - server.serve_forever() + server.serve_forever()
\ No newline at end of file |