Skip to content

Commit

Permalink
Update mock_server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nooblong committed Sep 19, 2023
1 parent 1e138a0 commit eb45897
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 153 deletions.
153 changes: 0 additions & 153 deletions main.py

This file was deleted.

35 changes: 35 additions & 0 deletions mock_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
from sys import argv


class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()

def do_GET(self):
self._set_headers()

def do_HEAD(self):
self._set_headers()

def do_POST(self):
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length)
self._set_headers()
print(post_data.decode("unicode_escape"))


def run(server_class=HTTPServer, handler_class=S, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print('Starting httpd...')
httpd.serve_forever()


if __name__ == '__main__':
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()

0 comments on commit eb45897

Please sign in to comment.