Skip to content

Commit

Permalink
Fix stop bug, Add OPTIONS, POST, PUT support
Browse files Browse the repository at this point in the history
  • Loading branch information
learning committed Mar 5, 2016
1 parent 8a44dce commit f0206d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
35 changes: 27 additions & 8 deletions SublimeServer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ------------------------------------------------------------------------------
# SublimeServer 0.3.2
# SublimeServer 0.3.3
# ------------------------------------------------------------------------------
__VERSION__ = "0.3.2"
__VERSION__ = "0.3.3"

import os
import sys
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -245,11 +266,11 @@ def send_md(self):
<script src="/markdown.js"></script>
<script>
window.addEventListener('load', function() {
var markdown_src=document.getElementById("markdown").textContent;
var markdown_src = document.getElementById("markdown").textContent;
var preview = document.getElementById("preview");
preview.innerHTML = markdown.toHTML(markdown_src);
}) ;
</script>
preview.innerHTML = markdown.toHTML(markdown_src);
});
</script>
</body>
</html>
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f0206d3

Please sign in to comment.