diff --git a/README.md b/README.md index 1e1dcce..62f71b9 100755 --- a/README.md +++ b/README.md @@ -74,4 +74,4 @@ Know issues: - While dragging new folders to Sublime or remove folders from Sublime, SublimeServer cannot refresh it.(#4) -### For more details please visit http://learning.github.com/SublimeServer +### For more details please visit [http://learning.github.com/SublimeServer](http://learning.github.com/SublimeServer) diff --git a/SublimeServer.py b/SublimeServer.py index 3cb73ed..fb26f9a 100755 --- a/SublimeServer.py +++ b/SublimeServer.py @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------------ -# SublimeServer 0.3.2 +# SublimeServer 0.3.3 # ------------------------------------------------------------------------------ -__VERSION__ = "0.3.2" +__VERSION__ = "0.3.3" import os import sys @@ -170,6 +170,23 @@ def do_GET(self): finally: f.close() + def do_OPTIONS(self): + """Serve a OPTIONS request.""" + self.send_response(200, "ok") + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS') + self.send_header("Access-Control-Allow-Headers", "X-Requested-With") + self.send_header("Access-Control-Allow-Headers", "Content-Type") + self.end_headers() + + def do_POST(self): + """Serve a POST request.""" + self.do_GET() + + def do_PUT(self): + """Serve a PUT request.""" + self.do_GET() + def do_HEAD(self): """Serve a HEAD request.""" f = self.send_head() @@ -225,6 +242,10 @@ def send_head(self): self.send_header("Content-type", ctype) fs = os.fstat(f.fileno()) self.send_header("Content-Length", str(fs[6])) + self.send_header("Access-Control-Allow-Origin", "*") + self.send_header("Cache-Control", "no-cache, no-store, must-revalidate") + self.send_header("Pragma", "no-cache") + self.send_header("Expires", "0") self.send_header( "Last-Modified", self.date_time_string(fs.st_mtime)) self.end_headers() @@ -245,11 +266,11 @@ def send_md(self): + preview.innerHTML = markdown.toHTML(markdown_src); + }); + """ @@ -411,12 +432,10 @@ def __init__(self): def run(self): self.httpd.serve_forever() - self._stop = threading.Event() def stop(self): self.httpd.shutdown() self.httpd.server_close() - self._stop.set() class SublimeserverStartCommand(sublime_plugin.ApplicationCommand):