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.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
saGii
  • 447
  • 5
  • 14
  • 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. – Schlangi Mar 15 '13 at 08:45

1 Answers1

1

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

# encoding: utf-8
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
  • already did. Missed out when listing things i had tried. Infact it was the first thing i did. – saGii Mar 04 '13 at 15:55