Reputation: 629
I am making a CORS request which returns a 202 empty response with a location header to query for data.
But the browser is not redirecting to the url in the location header. Tried it on Chrome/Firefox and it does the same.
jQuery.ajax(url, options).done((result: any) => {
});
.done gets called immediately after 202 response
Upvotes: 0
Views: 1592
Reputation: 56477
Have a look at the HTTP specification, especially this part:
14.30 Location
The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request. For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource. The field value consists of a single absolute URI.
Since automatic redirection is only mentioned for 3xx responses (actually I've checked entire spec) then it means that for any other status code it depends on browser. Wikipedia also confirms that:
To provide information about the location of a newly created resource. In this circumstance, the Location header should be sent with an HTTP status code of 201 or 202
I think it is safe to assume that that's just how browsers work. You will have to redirect manually.
Upvotes: 2