Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/goliath/rack/jsonp.rb doesn’t set Content-Type: application/javascript #126

Closed
peterhellberg opened this issue Jan 5, 2012 · 6 comments

Comments

@peterhellberg
Copy link

If JavaScript is returned (which is what JSONP is), then the content type should be set to application/javascript as per rfc4329.txt.

Is there a reason why jsonp.rb doesn’t change the content type?

@igrigorik
Copy link
Member

Likely an oversight / omission on our part.

@dj2
Copy link
Contributor

dj2 commented Jan 6, 2012

The jsonp middleware doesn't actually format the response as JSON. It just warps the jsonp callback around whatever the current response is. You would also need to use the JSON formatter (after jsonp in the list of middlewares).

@dj2 dj2 closed this as completed Jan 6, 2012
@peterhellberg
Copy link
Author

@dj2 That is very true, but if you set the content type to application/json in your response and use the JSONP middleware with the JSON formatter it outputs text that isn’t valid JSON (Nor should it). This is why I wondered if we should change the behavior of the JSONP-middleware to change the content type to application/javascript as this is more in line with what is sent down the pipe.

@dj2
Copy link
Contributor

dj2 commented Jan 6, 2012

I'd call that a bug in your application if you're setting the wrong content-type. The json formatter will accept either application/json or application/javascript and format them as JSON.

@peterhellberg
Copy link
Author

Ok, so you think it is better to check if env.params['callback'] is set and then change the content type to application/javascript instead of doing the same thing inside of the JSONP middleware? I just thought it would be more convenient if the JSONP middleware changed the content type when checking if a callback was provided.

@igrigorik
Copy link
Member

I agree, the JSONP middleware should set the appropriate header, which in this case is application/javascript, as per spec: http://tools.ietf.org/html/rfc4329

I wouldn't bake this directly into the JSON middleware, since there is a chance that you may want to use callback param for something else.

@igrigorik igrigorik reopened this Jan 7, 2012
@dj2 dj2 closed this as completed in 65440bd Jan 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants