0

I was trying to open a small and simple http server to share some files on LAN (or online on public IP). On a bit of research i found python -m SimpleHTTPServer does the job but it has horrible concurrent request issues. Users tell me that when they're downloading a file (typically large file, like movies), the browsing becomes extremely slow.

Being a rails programmer myself, i found this:

s=WEBrick::HTTPServer.new({DocumentRoot: ".", Port: 8000 })
trap("INT"){s.shutdown}
s.start

This was perfect with regards to being simple and didn't have problems like python's. However there's one thing that has me baffled. When filenames on my Ubuntu has characters that aren't ascii encoded it throws error: invalid byte sequence in US-ASCII.

My search into the webrick gem revealed it assumes a US-ASCII encoding. I wonder why not UTF-8. I tried stuff including:

  1. At the start of my ruby file:

    Encoding.default_external = Encoding::UTF_8
    Encoding.default_internal = Encoding::UTF_8
    
  2. in ubuntu environment:

    export LANGUAGE=en_US.UTF-8
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    
  3. Iconv conversions

and God knows what else in the 4 hours i've been on it.

I really don't understand how I can tell webrick to use utf-8 character encoding for its server.

1
  • It is not clear to me, if you have written an own new Rails app, or if you simply use WEBrick for serving your files. The first thing you should clarify is, which encoding the filenames nativly have on disk. It seems to me that the source is not UTF-8 but something different. So you have to tell your WEBrick, that the source string encoding is X and then you have to encode it to utf-8 for your webserver page. Commented Mar 15, 2013 at 8:45

1 Answer 1

1

Try adding the “magic” comment at the top of your file:

# encoding: utf-8
Sign up to request clarification or add additional context in comments.

1 Comment

already did. Missed out when listing things i had tried. Infact it was the first thing i did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.