Last active
November 19, 2024 10:11
-
-
Save chrisbolin/2e90bc492270802d00a6 to your computer and use it in GitHub Desktop.
Revisions
-
chrisbolin revised this gist
Jan 22, 2016 . No changes.There are no files selected for viewing
-
chrisbolin revised this gist
Oct 20, 2014 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,14 @@ ''' Taken from: http://stackoverflow.com/users/1074592/fakerainbrigand http://stackoverflow.com/questions/15401815/python-simplehttpserver ''' import SimpleHTTPServer, SocketServer import urlparse, os PORT = 3000 INDEXFILE = 'index.html' class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): @@ -21,11 +21,12 @@ def do_GET(self): # File exists, serve it up SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self); else: # send index.html, but don't redirect self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() with open(INDEXFILE, 'r') as fin: self.copyfile(fin, self.wfile) Handler = MyHandler -
chrisbolin renamed this gist
Oct 19, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
chrisbolin created this gist
Oct 19, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ ''' Taken from: http://stackoverflow.com/users/993133/pd40 http://stackoverflow.com/questions/15401815/python-simplehttpserver ''' import SimpleHTTPServer, SocketServer import urlparse, os PORT = 3000 INDEXFILE = '/index.html' class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): # Parse query data to find out what was requested parsedParams = urlparse.urlparse(self.path) # See if the file requested exists if os.access('.' + os.sep + parsedParams.path, os.R_OK): # File exists, serve it up SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self); else: # redirect to index.html self.send_response(302) self.send_header('Content-Type', 'text/html') self.send_header('location', INDEXFILE) self.end_headers() Handler = MyHandler httpd = SocketServer.TCPServer(("", PORT), Handler) print "serving at port", PORT httpd.serve_forever()