Permalink
Browse files

`server` function: Set the default Content-Type to `text/plain` inste…

  • Loading branch information...
1 parent 9850a48 commit c1c05cb460d88c6611f18265b485e0e90c3b45c9 @mathiasbynens committed Dec 31, 2011
Showing with 3 additions and 1 deletion.
  1. +3 −1 .functions
View
@@ -6,7 +6,9 @@ function md() {
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
- open "http://localhost:${port}/" && python -m SimpleHTTPServer "$port"
+ open "http://localhost:${port}/"
+ # Set the default Content-Type to `text/plain` instead of `application/octet-stream`
+ python -c "import SimpleHTTPServer; import sys; sys.argv = [None, '$port']; SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map[''] = 'text/plain'; SimpleHTTPServer.test();"
}
# Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.

3 comments on commit c1c05cb

Contributor

janmoesen replied Jan 2, 2012

Would it be reasonable to ass-u-me UTF-8 and go for text/plain; charset=UTF-8?

Owner

mathiasbynens replied Jan 2, 2012

I suppose it would, but I was unsure whether SimpleHTTPServer ever sets a charset by default by appending to the default Content-Type. Wouldn’t want to end up with headers like Content-Type: text/plain;charset=UTF-8;charset=UTF-8 — not sure how UAs would interpret that.

Now that I think about it, that was probably not a realistic assumption. Fixed in ec4b44e, thanks!

Owner

mathiasbynens replied Jan 2, 2012

That said, if anyone knows of a way to force charset=UTF-8 for all files served through SimpleHTTPServer, please share!

Please sign in to comment.