Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Changed the return type of json to "text/javascript" #94

Closed
wants to merge 5 commits into from

3 participants

@matthusby

In (older?) IE if the content type is set to application/json IE doesn't know what to do with it so it tries to download the file instead of just pass it back to the js function. Changing it to a content type that ie understands fixes the problem.

@nyaray

Please, don't do this.

While I see the value of supporting some of IEs quirks I can't really view this as defendable behaviour within a reasonable extent. Breaking this standard compliance ("The MIME media type for JSON text is application/json." ((emphasis added)), http://www.ietf.org/rfc/rfc4627.txt.pdf, page 6) is a sure-fire way of setting CB on the path to obscurity since it just opens a can of worms with bad hacks and "compliance fixes".

My suggestion is that you add a user agent sniff somewhere in your code path that checks if the user is running a dinosaur version of IE instead of breaking CB.

Cheers,
Emilio

EDIT: minor spelling/grammar

@evanmiller
Owner

Matt -- can you use an after filter to fix the MIME type? e.g.

after_(_, {Status, Headers, Payload}) ->
case my_lib:is_user_agent_internet_explorer(Req) of
true ->
{Status, my_lib:replace_application_json_with_text_javascript(Headers), Payload};
fals ->
{Status, Headers, Payload}
end.

@matthusby

Emilio: Ah yeah good call, perhaps we can look at the "Accept" header to find out if the client can accept "application/json" and then fall back to something else if it cant (text/plain)?

Evan: Thanks I will take a look at that in the short term. Any thoughts on above?

@evanmiller
Owner

Matt: I would be OK with a solution that sets the MIME type based on the requester's capabilities, so long as the MIME type can still be manually overridden.

Emilio: In my experience, mature software is filled with "ugly hacks" that allow interoperability with the widest ecosystem. I prefer to have things "just work" even if it means occasionally adding a few lines of code I wish weren't necessary.

@nyaray

Matt: yeah, something like that would be more appropriate (in my opinion, in this particular case). I also realise I might have phrased my response to harshly/directly at the core issue, sorry if my knee-jerk came on too strong.

Evan: I understand where you're coming from with that. Since we're not dealing with a web server but a framework I guess it makes sense to make things "just work" as you're saying.

I haven't dug that far into the inner workings of CB, but I'm sure that you know where a fix for this issue "should" (:P) be introduced.

@evanmiller
Owner

Emilio: Well, if you think web servers are browser-agnostic, try grepping the Nginx source code for the phrase "MSIE". I get 88 hits :-)

It looks like Matt knows his way around this part of the code so I will await an update pull request from him.

@matthusby

Emilio: No worries :-)

Evan: I will try to take a look early this week. As far as knowing the code, its just enough to be dangerous ;-) but I will certainly give it a shot.

@nyaray

Evan: you just broke me, but I think I'll get over it, though ;P.

Matt: coolios, good luck with the patch :).

@matthusby

Hey guys, sorry I haven't had a chance to look this over yet (ended up traveling last week, and starting a new job next week) so I am hoping to get around to this next weekend.

@evanmiller
Owner

Any updates, @matthusby?

@matthusby

Hey @evanmiller, sorry - I really have not been keeping up with CB like I should be :(

I don't have any patches for this (and no plans currently) - I just hard coded the content-type change into my fork for the application I had problems with.

@evanmiller
Owner

Since this can be fixed with the after_ filter I am closing the issue. If someone cares enough to send me a patch I will consider it.

@evanmiller evanmiller closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2012
  1. @matthusby

    Changed the return type of json to "text/javascript" so that IE doesn…

    matthusby authored
    …'t try to download the return
Commits on Jul 16, 2012
  1. @evanmiller

    Merge pull request #121 from mihawk/master

    evanmiller authored
    add cowboy support using mochicow
  2. @evanmiller

    Document cowboy support

    evanmiller authored
Commits on Jul 18, 2012
  1. @matthusby

    Changed the return type of json to "text/javascript" so that IE doesn…

    matthusby authored
    …'t try to download the return
  2. @matthusby

    Merge branch 'application_json_fix' of github.com:matthusby/ChicagoBo…

    matthusby authored
    …ss into application_json_fix
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 2 deletions.
  1. +2 −1  doc-src/api-config.html
  2. +1 −1  src/boss/boss_web_controller.erl
View
3  doc-src/api-config.html
@@ -37,8 +37,9 @@
<li><code>port</code> - The port to run the HTTP server on, or a tuple of the format {env, "PORTVAR"} (where PORTVAR is the name of an environment variable containing the port number). Defaults to 8001.</li>
<li><code>server</code> - The HTTP server to use. Valid values are:
<ul>
- <li><code>mochiweb</code> - The <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> Web Server</li>
+ <li><code>cowboy</code> - The <a href="https://github.com/extend/cowboy/">Cowboy</a> Web Server</li>
<li><code>misultin</code> - The <a href="http://code.google.com/p/misultin/">Misultin</a> Web Server</li>
+ <li><code>mochiweb</code> - The <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> Web Server</li>
</ul>
<li><code>base_url</code>Sets the base_url passed to the views (for deployments on suburl's)</li>
<li><code>session_adapter</code> Selects the session driver to use. Valid values:</li>
View
2  src/boss/boss_web_controller.erl
@@ -730,7 +730,7 @@ process_action_result(Info, {json, Data}, ExtraHeaders, AppInfo, AuthInfo) ->
process_action_result(Info, {json, Data, []}, ExtraHeaders, AppInfo, AuthInfo);
process_action_result(Info, {json, Data, Headers}, ExtraHeaders, AppInfo, AuthInfo) ->
process_action_result(Info, {output, boss_json:encode(Data, AppInfo#boss_app_info.model_modules),
- merge_headers(Headers, [{"Content-Type", "application/json"}])}, ExtraHeaders, AppInfo, AuthInfo);
+ merge_headers(Headers, [{"Content-Type", "text/javascript"}])}, ExtraHeaders, AppInfo, AuthInfo);
process_action_result(Info, {jsonp, Callback, Data}, ExtraHeaders, AppInfo, AuthInfo) ->
process_action_result(Info, {jsonp, Callback, Data, []}, ExtraHeaders, AppInfo, AuthInfo);
Something went wrong with that request. Please try again.