Skip to content

Commit ace61ca

Browse files
author
tony
committed
http/https Util
0 parents  commit ace61ca

File tree

9 files changed

+64
-0
lines changed

9 files changed

+64
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

HTTPS_Server.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import BaseHTTPServer,SimpleHTTPServer,SocketServer
2+
import logging
3+
import cgi
4+
import sys
5+
import socket
6+
import ssl
7+
8+
PORT = int(sys.argv[1])
9+
10+
def staticHttpServer(req):
11+
logging.warning(req.headers)
12+
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(req)
13+
14+
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
15+
16+
def do_GET(self):
17+
"do something for GET"
18+
staticHttpServer(self)
19+
def do_POST(self):
20+
"do something for POST"
21+
staticHttpServer(self)
22+
23+
Handler = ServerHandler
24+
25+
httpd = BaseHTTPServer.HTTPServer(("", PORT),Handler)
26+
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./cert.pem', server_side=True)
27+
ip = socket.gethostbyname(socket.gethostname())
28+
print "Serving at: https://%(interface)s:%(port)s" % dict(interface=ip or "localhost", port=PORT)
29+
httpd.serve_forever()

HTTP_Server.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import SimpleHTTPServer
2+
import SocketServer
3+
import logging
4+
import cgi
5+
import sys
6+
import socket
7+
8+
PORT = int(sys.argv[1])
9+
10+
def staticHttpServer(req):
11+
logging.warning(req.headers)
12+
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(req)
13+
14+
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
15+
16+
def do_GET(self):
17+
"do something for GET"
18+
staticHttpServer(self)
19+
def do_POST(self):
20+
"do something for POST"
21+
staticHttpServer(self)
22+
23+
Handler = ServerHandler
24+
25+
httpd = SocketServer.TCPServer(("", PORT), Handler)
26+
ip = socket.gethostbyname(socket.gethostname())
27+
print "Serving at: http://%(interface)s:%(port)s" % dict(interface=ip or "localhost", port=PORT)
28+
httpd.serve_forever()

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout cert.pem -out cert.pem

clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm *.pem *.out

startHttpServer.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pushd ./resource
2+
nohup python ../HTTP_Server.py 8001 &> ../nohup.out &

startHttpsServer.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nohup python HTTPS_Server.py 8002 &

stopHttpServer.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kill $(ps aux | grep '[H]TTP_Server' | awk '{print $2}')

stopHttpsServer.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kill $(ps aux | grep '[H]TTPS_Server' | awk '{print $2}')

0 commit comments

Comments
 (0)