Skip to content

Commit

Permalink
dummy http server
Browse files Browse the repository at this point in the history
  • Loading branch information
romannurik committed Feb 3, 2020
1 parent ccc63eb commit 0ffa064
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bin/dummy_http_server.py
@@ -0,0 +1,30 @@
#!/usr/bin/env python3.7
from http.server import HTTPServer, BaseHTTPRequestHandler

from io import BytesIO



class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'Hello, world!')

def do_POST(self):
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length)
self.send_response(200)
self.end_headers()
response = BytesIO()
response.write(b'This is POST request. ')
response.write(b'Received: ')
response.write(body)
print(self.headers)
print(body)
self.wfile.write(response.getvalue())


httpd = HTTPServer(('localhost', 8100), SimpleHTTPRequestHandler)
httpd.serve_forever()

0 comments on commit 0ffa064

Please sign in to comment.