rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* Rack::JSONP breaks Rack::Mime by mutating content type
@ 2010-08-12 16:22 Samuel Lebeau
  0 siblings, 0 replies; only message in thread
From: Samuel Lebeau @ 2010-08-12 16:22 UTC (permalink / raw)
  To: Rack Development

Hello,

I've filed a ticket on Github [1] but realized later that the
preferred way is to post a message here.
Here is the issue: `Rack::JSONP` uses `gsub!` to change content type,
which has the disastrous effect of altering
`Rack::Mime::MIME_TYPES['.json']`.

Say you're using Sinatra, with `content_type :json` in some route's
block, it looks up `MIME_TYPES` under the hood, which is then mutated
by `JSONP`: subsequent requests are then served as javascript and are
ignored by the middleware.

IMHO it should use `gsub` instead (I can see no reason for Sinatra to
duplicate the mime type upstream), and `Rack::Mime::MIME_TYPES` could
even `freeze` its content type strings to prevent this kind of errors.

I've made a patch on my fork, I hope this will be useful [2].

Best,
Samuel.

[1] http://github.com/rack/rack-contrib/issues/9
[2] http://github.com/samleb/rack-contrib/commit/2921c9e78b6c473d5d42162a2c33ac90773ce291

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-08-12 16:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 16:22 Rack::JSONP breaks Rack::Mime by mutating content type Samuel Lebeau

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).