Skip to content

Loading…

Make bin/serve serve everything as UTF-8 by default. #3

Closed
wants to merge 1 commit into from

2 participants

@mathiasbynens

This was a fun way to learn a bit of Python :) Thanks!

@cowboy
Owner

What happens when you serve binaries like images or .zip files?

@mathiasbynens

Seems to work fine for all kinds of binary files — only tested in Chrome though.

@cowboy
Owner

Yeah, but this isn't the only one, believe me.

@cowboy cowboy closed this in c7fcdd1
@cowboy
Owner

(FWIW, he convinced me in IRC in about 10 seconds)

@ytjohn ytjohn pushed a commit to ytjohn/dotfiles that referenced this pull request
@cowboy Incorporating suggestions from @mathiasbynens. Closes #3. 28db803
@ytjohn ytjohn pushed a commit to ytjohn/dotfiles that referenced this pull request
@cowboy Merge branch 'serve'
* serve:
  Incorporating suggestions from @mathiasbynens. Closes #3.
  Rewriting bin/serve in python, because.. well, why not?
321d7cd
@andornaut andornaut pushed a commit that referenced this pull request
@cowboy Merge branch 'serve'
* serve:
  Incorporating suggestions from @mathiasbynens. Closes #3.
  Rewriting bin/serve in python, because.. well, why not?
67b07cd
@andornaut andornaut pushed a commit that referenced this pull request
@cowboy Merge branch 'serve'
* serve:
  Incorporating suggestions from @mathiasbynens. Closes #3.
  Rewriting bin/serve in python, because.. well, why not?
76859e5
@jesperronn jesperronn pushed a commit to jesperronn/cowboy-dotfiles that referenced this pull request
@cowboy Incorporating suggestions from @mathiasbynens. Closes #3. 925cc19
@jesperronn jesperronn pushed a commit to jesperronn/cowboy-dotfiles that referenced this pull request
@cowboy Merge branch 'serve'
* serve:
  Incorporating suggestions from @mathiasbynens. Closes #3.
  Rewriting bin/serve in python, because.. well, why not?
2459535
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 6 additions and 2 deletions.
  1. +6 −2 bin/serve
View
8 bin/serve
@@ -33,8 +33,12 @@ file=$1
python=$(cat <<'PYTHON'
# Import the module so it can be used.
import SimpleHTTPServer
-# Set the default content type.
-SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map[""] = "text/plain"
+map = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map
+# Set the default content type to text/plain.
+map[""] = "text/plain"
+# Serve everything as UTF-8 by default.
+for key, value in map.items():
+ map[key] = value + ';charset=UTF-8'
# Start the server (the port is still grabbed from sys.argv[1]).
SimpleHTTPServer.test()
PYTHON
Something went wrong with that request. Please try again.