forked from zephyrproject-rtos/net-tools
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps-server.py
More file actions
Latest commit
executable file
·51 lines (42 loc) · 1.42 KB
/
Copy pathhttps-server.py
File metadata and controls
executable file
·51 lines (42 loc) · 1.42 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# HTTPS server test application.
#
# You can generate certificate file like this:
# openssl req -x509 -newkey rsa:2048 -keyout https-server.pem \
# -out https-server.pem -days 10000 -nodes \
# -subj '/CN=localhost'
#
# To see the contents of the certificate do this:
# openssl x509 -in https-server.pem -text -noout
#
# To add the cert into your application do this:
# openssl x509 -in https-server.pem -C -noout
#
importsocket
fromBaseHTTPServerimportHTTPServer
fromSimpleHTTPServerimportSimpleHTTPRequestHandler
importssl
PORT=4443
classHTTPServerV6(HTTPServer):
address_family=socket.AF_INET6
classRequestHandler(SimpleHTTPRequestHandler):
length=0
def_set_headers(self):
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', str(self.length))
self.end_headers()
defdo_POST(self):
payload="<html><p>Done</p></html>"
self.length=len(payload)
self._set_headers()
self.wfile.write(payload)
defmain():
httpd=HTTPServerV6(("", PORT), RequestHandler)
print"Serving at port", PORT
httpd.socket=ssl.wrap_socket(httpd.socket,
certfile='./https-server.pem',
server_side=True)
httpd.serve_forever()
if__name__=='__main__':
main()