Skip to content

Commit f0206d3

Browse files
committed
Fix stop bug, Add OPTIONS, POST, PUT support
1 parent 8a44dce commit f0206d3

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ Know issues:
7474
- While dragging new folders to Sublime or remove folders from Sublime, SublimeServer cannot refresh it.(#4)
7575

7676

77-
### For more details please visit http://learning.github.com/SublimeServer
77+
### For more details please visit [http://learning.github.com/SublimeServer](http://learning.github.com/SublimeServer)

SublimeServer.py

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ------------------------------------------------------------------------------
2-
# SublimeServer 0.3.2
2+
# SublimeServer 0.3.3
33
# ------------------------------------------------------------------------------
4-
__VERSION__ = "0.3.2"
4+
__VERSION__ = "0.3.3"
55

66
import os
77
import sys
@@ -170,6 +170,23 @@ def do_GET(self):
170170
finally:
171171
f.close()
172172

173+
def do_OPTIONS(self):
174+
"""Serve a OPTIONS request."""
175+
self.send_response(200, "ok")
176+
self.send_header('Access-Control-Allow-Origin', '*')
177+
self.send_header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS')
178+
self.send_header("Access-Control-Allow-Headers", "X-Requested-With")
179+
self.send_header("Access-Control-Allow-Headers", "Content-Type")
180+
self.end_headers()
181+
182+
def do_POST(self):
183+
"""Serve a POST request."""
184+
self.do_GET()
185+
186+
def do_PUT(self):
187+
"""Serve a PUT request."""
188+
self.do_GET()
189+
173190
def do_HEAD(self):
174191
"""Serve a HEAD request."""
175192
f = self.send_head()
@@ -225,6 +242,10 @@ def send_head(self):
225242
self.send_header("Content-type", ctype)
226243
fs = os.fstat(f.fileno())
227244
self.send_header("Content-Length", str(fs[6]))
245+
self.send_header("Access-Control-Allow-Origin", "*")
246+
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
247+
self.send_header("Pragma", "no-cache")
248+
self.send_header("Expires", "0")
228249
self.send_header(
229250
"Last-Modified", self.date_time_string(fs.st_mtime))
230251
self.end_headers()
@@ -245,11 +266,11 @@ def send_md(self):
245266
<script src="/markdown.js"></script>
246267
<script>
247268
window.addEventListener('load', function() {
248-
var markdown_src=document.getElementById("markdown").textContent;
269+
var markdown_src = document.getElementById("markdown").textContent;
249270
var preview = document.getElementById("preview");
250-
preview.innerHTML = markdown.toHTML(markdown_src);
251-
}) ;
252-
</script>
271+
preview.innerHTML = markdown.toHTML(markdown_src);
272+
});
273+
</script>
253274
</body>
254275
</html>
255276
"""
@@ -411,12 +432,10 @@ def __init__(self):
411432

412433
def run(self):
413434
self.httpd.serve_forever()
414-
self._stop = threading.Event()
415435

416436
def stop(self):
417437
self.httpd.shutdown()
418438
self.httpd.server_close()
419-
self._stop.set()
420439

421440

422441
class SublimeserverStartCommand(sublime_plugin.ApplicationCommand):

0 commit comments

Comments
 (0)