Skip to content

Commit

Permalink
Cleanup. Move note files into docs/.
Browse files Browse the repository at this point in the history
  • Loading branch information
kanaka committed May 1, 2010
1 parent adfe6ac commit 5aca52e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 137 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 0 additions & 39 deletions prime.html

This file was deleted.

39 changes: 0 additions & 39 deletions prime.js

This file was deleted.

51 changes: 45 additions & 6 deletions web.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
#!/usr/bin/python
'''
A super simple HTTP/HTTPS webserver for python. Automatically detect
import sys
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
You can make a cert/key with openssl using:
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
as taken from http://docs.python.org/dev/library/ssl.html#certificates
'''

import traceback, sys
import socket
import ssl
#import http.server as server # python 3.X
import SimpleHTTPServer as server # python 2.X

def do_request(connstream, from_addr):
x = object()
server.SimpleHTTPRequestHandler(connstream, from_addr, x)

def serve():
bindsocket = socket.socket()
#bindsocket.bind(('localhost', PORT))
bindsocket.bind(('', PORT))
bindsocket.listen(5)

print("serving on port", PORT)

while True:
try:
newsocket, from_addr = bindsocket.accept()
peek = newsocket.recv(1024, socket.MSG_PEEK)
if peek.startswith("\x16"):
connstream = ssl.wrap_socket(
newsocket,
server_side=True,
certfile='self.pem',
ssl_version=ssl.PROTOCOL_TLSv1)
else:
connstream = newsocket

do_request(connstream, from_addr)

except Exception:
traceback.print_exc()

try:
port = int(sys.argv[1])
PORT = int(sys.argv[1])
except:
print "%s port" % sys.argv[0]
sys.exit(2)

server = HTTPServer(('',port), CGIHTTPRequestHandler)
server.serve_forever()
serve()
53 changes: 0 additions & 53 deletions webs.py

This file was deleted.

0 comments on commit 5aca52e

Please sign in to comment.