-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (21 loc) · 871 Bytes
/
main.py
File metadata and controls
28 lines (21 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from http.server import HTTPServer, BaseHTTPRequestHandler
from http import cookies
class TestServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
# set a cookie with a name and value
cookie = cookies.SimpleCookie()
cookie['name'] = 'value'
# serve a response with cookies
self.send_header('Set-Cookie', cookie.output(header=''))
self.end_headers()
# For Python 3, prefix the string literals with a b:
self.wfile.write(b'<html><body>')
self.wfile.write(b'<h1>Hello World!</h1>')
self.wfile.write(b'</body></html>')
if __name__ == '__main__':
server_address = ('', 8000)
httpd = HTTPServer(server_address, TestServer)
print('Server listening on port 8000...')
httpd.serve_forever()