<?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>12607</bug_id>
          
          <creation_ts>2011-05-05 12:33:52 +0000</creation_ts>
          <short_desc>Let authors control redirect behavior</short_desc>
          <delta_ts>2014-02-03 18:16:42 +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="brunoais">brunoaiss</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>annevk</cc>
    
    <cc>baranovich</cc>
    
    <cc>brunoaiss</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>cowwoc</cc>
    
    <cc>hsteen</cc>
    
    <cc>julian.reschke</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>48083</commentid>
    <comment_count>0</comment_count>
    <who name="brunoais">brunoaiss</who>
    <bug_when>2011-05-05 12:33:52 +0000</bug_when>
    <thetext>I tried to find a better place to file this but I wasn&apos;t able to find it.

I&apos;d like to suggest to extend the specification
http://www.w3.org/TR/XMLHttpRequest/
-&gt;3. The XMLHttpRequest Interface
and in:
3.6.4. Infrastructure for the send() method
If the response has an HTTP status code of 301, 302, 303, or 307 

Proposal:
Add the an attribute: 
readwrite attribute followRedirects

What does it do?
This attribute states if the browser should follow location headers or not.

This attribute is only writable while state = 0.
This attribute defaults to true (for backwards compatibility and because the usual use is to work like this).


Why am I asking for this:
I have been writing browser addons for a while and now I&apos;m writing another one that uses unrestricted cross origin XMLHttpRequest(). The problem is that the page I want may return: 200, 302 or 304. When it returns 302 (usually) it redirects to a page that returns 302 and this repeats 2 more times. When there is a redirection, I&apos;m not interested anymore because it won&apos;t have the content I want.

My solution, for now:
1. Make the XMLHttpRequest()
2. Check the status code (for 200 or 304)
3. If it&apos;s 304, abort.
4. Execute a regex to check the responseText for a match.
5. If it&apos;s a match, then execute the code it should, else abort.

Problem: With all those redirects, the time the script uses, the CPU it uses and the number of requests it must make makes this background extension a really heavy duty for something as small as this is.

If this is approved I can make a much better code:
1. Make the XMLHttpRequest()
2. Check the status code (for 200, 302 or 304)
3. if it&apos;s 302 or 304 abort
4. execute the code it should

No regex -&gt; Much faster code
No unecessary redirects -&gt; Does not occupy the connections unecessary -&gt; Much faster code and more proper background execution.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48088</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-05-05 14:00:37 +0000</bug_when>
    <thetext>Note that if your addon is a Mozilla addon it can already prevent XHR from redirecting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48091</commentid>
    <comment_count>2</comment_count>
    <who name="brunoais">brunoaiss</who>
    <bug_when>2011-05-05 16:31:18 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Note that if your addon is a Mozilla addon it can already prevent XHR from
&gt; redirecting.

This one is a chrome extension.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48092</commentid>
    <comment_count>3</comment_count>
    <who name="brunoais">brunoaiss</who>
    <bug_when>2011-05-05 16:58:45 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #1)
&gt; &gt; Note that if your addon is a Mozilla addon it can already prevent XHR from
&gt; &gt; redirecting.
&gt; 
&gt; This one is a chrome extension.

I tried looking about this in the mozilla docs and I found nothing about how to prevent that redirection. Anyway, I think it would be useful to create a spec for it so that it would be normalized</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48093</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-05-05 17:08:07 +0000</bug_when>
    <thetext>In Mozilla, you can just register a redirect observer directly on the underlying nsIChannel.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50137</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-06-22 22:23:03 +0000</bug_when>
    <thetext>This is for the WebApps WG.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50138</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-06-22 22:24:50 +0000</bug_when>
    <thetext>See the archives of public-webapps@w3.org. Finding the right way to do this was harder than initially thought so the idea has been dropped for now. Having said that, extensions are not a use case for web platform extensions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63826</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-02-07 10:43:45 +0000</bug_when>
    <thetext>In particular anything we do here should take http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/thread.html#msg474 into consideration and in particular the emails from Darin Fisher.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83323</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-19 14:05:36 +0000</bug_when>
    <thetext>*** Bug 17046 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93849</commentid>
    <comment_count>9</comment_count>
    <who name="Gili">cowwoc</who>
    <bug_when>2013-09-26 02:24:45 +0000</bug_when>
    <thetext>I have a proposal that is similar to one originally brought up on the mailing list, but a bit different (I suspect Mozilla&apos;s implementation already works this way). Instead of adding a &quot;followRedirects&quot; flag and forcing users to issue new requests at each &quot;redirect hop&quot;, add a &quot;redirect observer&quot; as follows:

1. Allow users to register an event listener.
2. Every time the server returns a response, the event listener is fired with the response body and headers.
3. At this point, the listener may allow the request to continue or terminate it.
4. If the listener terminated the request, set readyState to some value that indicates the process was &quot;terminated by the user&quot;.
5. If the listener allows the request to continue and the response required a redirect, issue the new request and go to step #2.
6. Eventually no more redirects occur, and readyState is set to DONE as usual.

This would have the nice side-effect of addressing bug #23361 which I just filed.

Does this address everyone&apos;s use-cases?

I read the mailing list posts at http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/thread.html#msg474 but it wasn&apos;t clear why &quot;followRedirects&quot; ended up being removed from the standard. Anne, could you shed some light?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99609</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-02-03 11:07:10 +0000</bug_when>
    <thetext>Unfortunately redirects have to be atomic. See bug 24375.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99611</commentid>
    <comment_count>11</comment_count>
    <who name="Julian Reschke">julian.reschke</who>
    <bug_when>2014-02-03 11:52:39 +0000</bug_when>
    <thetext>Well, if authors can&apos;t control redirect behavior then the obvious alternate thing to ask for is to expose the redirect information after the request has finished. 

Does this have the same security concerns? If yes, we should have a precise description of what the problem is, so that a solution can address that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99620</commentid>
    <comment_count>12</comment_count>
    <who name="Gili">cowwoc</who>
    <bug_when>2014-02-03 17:58:44 +0000</bug_when>
    <thetext>I agree with Julian. This issue should be reopened and the browser should allow the user to read the final URL after redirection completes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99621</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-02-03 18:04:50 +0000</bug_when>
    <thetext>That is bug 15417.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99624</commentid>
    <comment_count>14</comment_count>
    <who name="Gili">cowwoc</who>
    <bug_when>2014-02-03 18:16:42 +0000</bug_when>
    <thetext>I stand corrected. Thanks Anne.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>