diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..35740e3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016-present Sanic Community + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README b/README index 53dda2b..602e172 100644 --- a/README +++ b/README @@ -1,6 +1,9 @@ httpserver ======================================= This httpserver is a enhanced version of SimpleHTTPServer. + It was write in python, I use some code from bottle[https://github.com/defnull/bottle] + It support resuming download, you can set the document root, it has more + friendly error hit, and it can handle mimetype gracefully diff --git a/httpserver.py b/httpserver.py index f2d43ef..db9d1e0 100755 --- a/httpserver.py +++ b/httpserver.py @@ -2,10 +2,9 @@ #coding=utf-8 ''' -For: by Lerry http://lerry.org Start from 2011/07/27 22:49:51 -Last edit at 2011/07/27 +Last edit at 2012/09/29 ''' import os import posixpath @@ -145,7 +144,7 @@ def send_head(self): return self.list_directory(path) mimetype = get_mime_type(path) - root = os.path.abspath(root_path) + os.sep + root = os.path.abspath(root_path) if not path.startswith(root): self.send_error(403, "Access denied.") @@ -160,6 +159,10 @@ def send_head(self): headers = dict(self.headers) fs = os.stat(path) + self.send_header("Content-Length", str(fs[6])) + self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) + self.send_header("Accept-Ranges", "bytes") + if 'if-modified-since' in headers: ims = headers['if-modified-since'] ims = parse_date(ims.split(";")[0].strip()) @@ -189,9 +192,6 @@ def send_head(self): self.send_header("Content-type", mimetype) #if encoding: # self.send_header("Content-Encoding", encoding) - self.send_header("Content-Length", str(fs[6])) - self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) - self.send_header("Accept-Ranges", "bytes") self.end_headers() result = StringIO() result.write(f) @@ -204,7 +204,7 @@ def translate_path(self, path): path = posixpath.normpath(urllib.unquote(path)) words = path.split('/') words = filter(None, words) - path = root_path#os.getcwd() + path = root_path for word in words: drive, word = os.path.splitdrive(word) head, word = os.path.split(word) @@ -217,11 +217,8 @@ def _test(self): headers = str(self.headers).split() print 'Range' in self.headers for index,data in enumerate(headers): - #print data if data.strip().lower().startswith('range'):#.startswith('range:'): - #print data, headers[index+1] pass - #print str(headers) return _RerootedHTTPRequestHandler class ThreadingServer(ThreadingMixIn, HTTPServer): @@ -231,7 +228,7 @@ class ThreadingServer(ThreadingMixIn, HTTPServer): def run(port=8080, doc_root=os.getcwd()): serveraddr = ('', port) serv = ThreadingServer(serveraddr, get_handler(doc_root)) - print 'Server Started at port:',port + print 'Server Started at port:', port serv.serve_forever() def test():