3

My web application works as follows:

  • /abc/xyz : response 301 permanent redirect Location : /abc/xyz/
  • /abc/xyz/ : appropriate response based on HTTP method requested

Now when I issue a request as follows:

dojo.xhr('PUT', {url : "/abc/xyz"})

The following sequene of operations happen automatically:

  • A PUT request is sent
  • A 301 permanent redirect is received
  • A GET request is sent to the new URL /abc/xyz/

I don't understand why this is happening. I don't wish dojo.xhr to be so smart. I wish it to just stop on 301 permanent redirect response and let me take care of how to handle permanent redirect. I would prefer to update the url and send a fresh PUT request in this case. The situation is same for all other HTTP methods like OPTIONS etc. I used PUT in above just as example.

Is there any option to configure dojo.xhr to behave like this?

Shailesh Kumar
  • 6,457
  • 8
  • 35
  • 60
  • I believe this is a browser issue, and not Dojo specific. See this question: http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call – Frode May 25 '11 at 22:43
  • This is also mentioned in 10.3.2 at http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html – Frode May 25 '11 at 22:45
  • @Frode, yes you are right. I also checked around and this seems to be the reason. – Shailesh Kumar May 28 '11 at 04:48

2 Answers2

0

If you really need to not follow a 301, you could create a gateway on the server side that returns a notice that a 301 was received instead of following it.

To do this with PHP and curl. see http://php.net/manual/en/ref.curl.php There is a get_url function in the comments

Ali Gangji
  • 1,463
  • 13
  • 22
0

This is a known issues in all browsers except IE (with a fix in the pipeline for Firefox).

In the meantime, if you really need the browser to follow the PUT redirect properly, you'll need to use status code 307.

See also http://trac.tools.ietf.org/wg/httpbis/trac/ticket/160 and http://trac.tools.ietf.org/wg/httpbis/trac/ticket/312

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98