<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19831</bug_id>
          
          <creation_ts>2012-11-02 15:14:14 +0000</creation_ts>
          <short_desc>Investigate overrideMimeType()</short_desc>
          <delta_ts>2013-05-23 10:33:26 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>XHR</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 3.1</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Anne">annevk</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>hsteen</cc>
    
    <cc>j</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>77752</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-02 15:14:14 +0000</bug_when>
    <thetext>Christophe Dumez informed me of https://bugs.webkit.org/show_bug.cgi?id=95728 which probably requires an answer and maybe a change in behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77753</commentid>
    <comment_count>1</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 15:56:55 +0000</bug_when>
    <thetext>I&apos;m about to write a couple of tests for overrideMimeType(), will report back on the behaviours..</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77755</commentid>
    <comment_count>2</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 16:17:43 +0000</bug_when>
    <thetext>(In any case spec is a bit inconsistent since it doesn&apos;t say anything about how overrideMimeType() behaves when send() flag is set in OPENED state - or for what&apos;s worth in HEADERS_RECEIVED state, this should be added.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77757</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-02 16:34:18 +0000</bug_when>
    <thetext>It&apos;s not inconsistent. The send() flag does not matter, the method just works. The method works working after all headers are in, because at that point you want to start using the MIME type.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77758</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-02 16:34:43 +0000</bug_when>
    <thetext>stops working*</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77761</commentid>
    <comment_count>5</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 17:04:20 +0000</bug_when>
    <thetext>For test calling overrideMimeType() at readyState=4, trying to make the browser handle a text/plain;charset=iso-8859-1 as if it were sent with application/xml;charset=UTF-8 :

IE 8 throws. End of story.

Firefox/Opera: don&apos;t throw. The call seems to have no effect whatsoever, neither on decoding nor on responseXML.

Chrome: oddly enough, Chrome does something inbetween. The new MIME type is applied, so request.responseXML is defined. The charset parameter has however no effect, so we get a well-formed XML DOM full of mojibake. :-p</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77762</commentid>
    <comment_count>6</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 17:06:58 +0000</bug_when>
    <thetext>(Test description should be: &quot;handle a text/plain;charset=iso-8859-1 as if it were application/xml;charset=Shift-JIS&quot;, I changed the test to better understand what was going on because Firefox seemed to do some encoding detection or normalisation somewhere)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77763</commentid>
    <comment_count>7</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 17:22:50 +0000</bug_when>
    <thetext>Anne: Firefox, Opera and Chrome agree that calling overrideMimeType() in HEADERS_RECEIVED state is a no-op.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77764</commentid>
    <comment_count>8</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-02 17:23:18 +0000</bug_when>
    <thetext>My preference would be to keep the exception throwing in the spec as-is. 

Reasons:

* calling a method when it has no effect is probably an author mistake, throwing is a better way to warn against it

* since IE does it, we will hopefully escape compat problems (and the method isn&apos;t much used in the first place)

* as implementations disagree, there is no clear, consistent and useful alternative behaviour to consistently throwing

I guess this E-mail caused the spec change to make it throw:
http://lists.w3.org/Archives/Public/public-webapps/2010OctDec/0022.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77814</commentid>
    <comment_count>9</comment_count>
    <who name="Julian Aubourg">j</who>
    <bug_when>2012-11-03 22:31:07 +0000</bug_when>
    <thetext>I think the wording in the spec is clear enough and that throwing an InvalidStateError makes perfect sense here.

As for the operation being a no-op in HEADERS_RECEIVED state, it&apos;s definitely a bug in FF, Opera and Chrome: inspecting headers then decide if overriding is needed/desired or not, and, more importantly, with which value seems like a very useful feature to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77979</commentid>
    <comment_count>10</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-06 22:10:19 +0000</bug_when>
    <thetext>D&apos;oh - IE (8) throws because this method isn&apos;t supported in IE at all.

I also note that no browser currently throws the prescribed SYNTAX_ERR for invalid MIME types. I hope we&apos;ll get away with it compat-wise, but we might not.

Julian, I think you said the method was more used than I thought - in among others jQuery. Any idea what the most commonly used argument strings are? Does jQuery&apos;s AJAX logic use overrideMimeType() internally?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77992</commentid>
    <comment_count>11</comment_count>
    <who name="Julian Aubourg">j</who>
    <bug_when>2012-11-07 13:08:35 +0000</bug_when>
    <thetext>&gt; D&apos;oh - IE (8) throws because this method isn&apos;t supported in IE at all.

Hahaha ;)

&gt; I also note that no browser currently throws the prescribed SYNTAX_ERR
&gt; for invalid MIME types. I hope we&apos;ll get away with it compat-wise, but
&gt; we might not.

They should :/

&gt; Julian, I think you said the method was more used than I thought - in
&gt; among others jQuery.

No, not quite. But we&apos;ve been asked to support it on our jqXHR abstraction so I know for a fact that our users have a need for it. That being said our implementation puts the new mimeType in an internal option and calls the native overrideMimeType before sending (see https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L78). We never had any complain about this... so I&apos;m not sure people are clamoring about what I&apos;m talking about in my previous comment (inspect response headers before deciding on the mimeType to override with if any).

&gt; Any idea what the most commonly used argument strings are?

No idea. I dunno if it is used to disable native XHR xml parsing or enable it or any other reason.

&gt; Does jQuery&apos;s AJAX logic use overrideMimeType() internally?

No, because it&apos;s not supported by all browsers we target as of today. This may change in jQuery 2.0. I&apos;d love to just force all requests in text/plain and have jQuery&apos;s own internal conversion logic handle parsing... would make our code that much simpler.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78097</commentid>
    <comment_count>12</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-09 12:02:44 +0000</bug_when>
    <thetext>Some new test cases now submitted and live:

http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-done-state.htm
http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-headers-received-state-force-shiftjis.htm
http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-invalid-mime-type.htm
http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-loading-state.htm
http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-open-state-force-utf-8.htm
http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-open-state-force-xml.htm
http://w3c-test.org/webapps/XMLHttpRequest/tests/submissions/Opera/overridemimetype-unsent-state-force-shiftjis.htm

They generally assert that the spec is correct as of now, including the headers-received state test (an assertation no browser actually passes, test added because Julian wants it to work :-))</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78098</commentid>
    <comment_count>13</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2012-11-09 12:08:38 +0000</bug_when>
    <thetext>&gt; I&apos;m not sure people are clamoring about
&gt; what I&apos;m talking about in my previous comment (inspect response headers
&gt; before deciding on the mimeType to override with if any).

Well, I&apos;ve never seen it done but the reason for that might of course be that it&apos;s generally not supported at all ;-)

I&apos;d like some implementor comments here, if possible.. The cost for implementors may not be worth the small extra benefit.

&gt; I&apos;d love to just force all requests in text/plain
&gt; and have jQuery&apos;s own internal conversion logic handle parsing...

Now, now.. usually JS authors want the browser to work harder and do more of the heavy lifting, so be careful what you ask for ;-)

Finally, overrideMimeType() is sort of obsolete with the responseType/response approach. The only remaining use case is to fix decoding of content with a misleading charset in content-type. Therefore, overrideMimeType() will hopefully be less and less used, so the details we&apos;re working on here aren&apos;t worth a lot more of our time IMO.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88121</commentid>
    <comment_count>14</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2013-05-23 10:33:26 +0000</bug_when>
    <thetext>As we largely agree that what the spec says is a reasonable idea, I&apos;ll WONTFIX this and we&apos;ll cross our fingers that there won&apos;t be much compat fallout..</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>