Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: tools/md_browser/md_browser.py

Issue 1786013003: [md_browser]: Sending header w/Content-Type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/md_browser/md_browser.py
diff --git a/tools/md_browser/md_browser.py b/tools/md_browser/md_browser.py
index 5ee2fa2c16c58184f18fa1ac209ced385ebcbbf5..2b968525320c8477f944307f599cc5178d69da94 100644
--- a/tools/md_browser/md_browser.py
+++ b/tools/md_browser/md_browser.py
@@ -92,7 +92,7 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
if not full_path.startswith(SRC_DIR):
self._DoUnknown()
elif path == '/doc.css':
- self._WriteTemplate('doc.css')
+ self._DoCSS('doc.css')
elif not os.path.exists(full_path):
self._DoNotFound()
elif path.lower().endswith('.md'):
@@ -122,16 +122,23 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
extension_configs=extension_configs,
output_format='html4').encode('utf-8')
try:
+ self._WriteHeader('text/html')
self._WriteTemplate('header.html')
self.wfile.write(md_fragment)
self._WriteTemplate('footer.html')
except:
raise
+ def _DoCSS(self, template):
+ self._WriteHeader('text/css')
+ self._WriteTemplate(template)
+
def _DoNotFound(self):
+ self._WriteHeader('text/html')
self.wfile.write('<html><body>%s not found</body></html>' % self.path)
def _DoUnknown(self):
+ self._WriteHeader('text/html')
self.wfile.write('<html><body>I do not know how to serve %s.</body>'
'</html>' % self.path)
@@ -141,6 +148,11 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
with codecs.open(path, encoding='utf-8') as fp:
return fp.read()
+ def _WriteHeader(self, content_type='text/plain'):
+ self.send_response(200)
+ self.send_header('Content-Type', content_type)
+ self.end_headers()
+
def _WriteTemplate(self, template):
contents = self._Read(os.path.join('tools', 'md_browser', template))
self.wfile.write(contents.encode('utf-8'))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698