Created
July 9, 2012 14:26
-
-
Save kgrz/3076865 to your computer and use it in GitHub Desktop.
Binary Post #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' # version: 1.4.0 and rack version: 1.4.1 | |
| post '/post' do | |
| request.body.each {|x| puts x.encoding} # each because the request is wrapped inside an object | |
| # that responds to each | |
| end | |
| __END__ | |
| `curl --data "Hello" http://localhost:9393/post` outputs "ASCII-8BIT" | |
| `curl --data-binary "Hello" http://localhost:9393/post` outputs "ASCII-8BIT" #No reason why I used that --data-binary handle | |
| `curl --data-binary @"two.txt" http://localhost:9393/post` works fine | |
| However, | |
| `curl --data-binary @"three.mp3" http://localhost:9393/post` fails with an ArgumentError: invalid byte sequence in UTF-8 and a stacktrace | |
| `curl --data-binary @"one.jpg" http://localhost:9393/post` fails with an ArgumentError: invalid byte sequence in UTF-8 and a stacktrace | |
| require 'sinatra' # version 1.3.2 rack 1.4.1 | |
| the same code above with both `ruby app.rb` and `shotgun app.rb` throws same error "invalid byte sequence in UTF-8" | |
| with locale settings (since using a commandline so that external encoding is specified) as LC_CTYPE=C | |
| `curl --data-binary @"three.mp3" http://localhost:9393/post` fails | |
| `curl --data-binary @"one.jpg" http://localhost:9393/post` fails | |
| with locale settings as LC_CTYPE="UTF-8" | |
| `curl --data-binary @"three.mp3" http://localhost:9393/post` gives the same error | |
| `curl --data-binary @"one.jpg" http://localhost:9393/post` gives the same error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment