response.parse raise an error when getting an image

66 views
Skip to first unread message

Juanito Fatas

unread,
May 13, 2016, 2:48:20 AM5/13/16
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hello, I use httprb gem to get an image then parse the response[1]:

response = HTTP.get "http://i.imgur.com/O602Rcm.jpg"
response.parse

But this raises an error.

HTTP::Error: Unknown MIME type: image/jpeg
from /Users/Juan/.gem/ruby/2.3.1/gems/http-2.0.0/lib/http/mime_type.rb:36:in `[]'
from /Users/Juan/.gem/ruby/2.3.1/gems/http-2.0.0/lib/http/response.rb:118:in `parse'
from (irb):61
from /Users/Juan/.gem/ruby/2.3.1/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /Users/Juan/.gem/ruby/2.3.1/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from /Users/Juan/.gem/ruby/2.3.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/Juan/.gem/ruby/2.3.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/Juan/.gem/ruby/2.3.1/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

Is this a bug?

Tony Arcieri

unread,
May 13, 2016, 12:37:08 PM5/13/16
to Juanito Fatas, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
On Thu, May 12, 2016 at 11:48 PM, Juanito Fatas <katehu...@gmail.com> wrote:
Hello, I use httprb gem to get an image then parse the response[1]:
HTTP::Error: Unknown MIME type: image/jpeg
Is this a bug?

No. The #parse method is for parsing text formats, such as JSON. There is no built-in parser in the library for JPEGs (what would it even do?) 

--
Tony Arcieri

Juanito Fatas

unread,
May 16, 2016, 12:09:24 AM5/16/16
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API, katehu...@gmail.com
Thank you for your response and sorry for my ignorance.

I was hoping to use `response.parse` in a consistent fashion to know if the response is success or not.

Tony Arcieri於 2016年5月14日星期六 UTC+8上午12時37分08秒寫道:
Reply all
Reply to author
Forward
0 new messages