Force JSON output and ignore any kind of content negotiation

22 views
Skip to first unread message

Travis Bell

unread,
Mar 4, 2014, 12:40:14 PM3/4/14
to golia...@googlegroups.com
Hey guys,

I have this as a simple little proxy: https://gist.github.com/travisbell/9349123

And while I understand this auto negotiates the content type (via the Accept header), we have many clients who don't have this set properly so we've historically had to force it to JSON no matter what. Since our API only returns JSON, this is a fairly safe thing for us to do.

This proxy works fine with cURL, but if I request it in Safari for example, I get:

[:error, "{\"status_code\"=>7, \"status_message\"=>\"Request Timed Out\"}"]

How can I skip the auto-negotiating nature of this and force it? Safari is a good example if a client that is apparently negotiating plain text.

Thanks!

Ilya Grigorik

unread,
Mar 4, 2014, 3:47:04 PM3/4/14
to golia...@googlegroups.com
Remove render middleware? If you do though, you're on your own to force /
negotiate the right response.

As a rule of thumb, if you're using "render" you probably also want to use
the DefaultMimeType middleware:
https://github.com/postrank-labs/goliath/blob/master/examples/async_upload.rb#L8

ig


--
You received this message because you are subscribed to the Google Groups "Goliath.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goliath-io+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Travis Bell

unread,
Mar 5, 2014, 9:46:35 AM3/5/14
to golia...@googlegroups.com
Ok, thanks Ilya.

I was hoping to use the stuff that was already built but it's not a big deal having to do it on my own.

Cheers!
Reply all
Reply to author
Forward
0 new messages