- March 16, 2011
- Not specified
- ajax redirect headers
- 1 (after 1 ratings)
Firefox transparently follows redirects when AJAX calls return 3xx code. And it drops additional headers, X-Requested-With among them. Server treats redirected HTTP requested as non-AJAX. JS libraries has nothing to do here.
At 16.03.11 bug https://bugzilla.mozilla.org/show_bug.cgi?id=553888 has status "NEW" being reported at 21.03.10.
Workaround is following: - in process_response(): if request.is_ajax() and response has status_code 3xx then put response["Location"] to session, otherwise unset session stored value (if it is there). - in process_request(): if not request.is_ajax() and request.path equals to stored session value then monkeypatch request.is_ajax() return True (before any views come into play).
This results in smooth transparent redirects in Firefox, all treated as AJAX calls.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class FixFirefoxMissingAJAXRedirectHeadersMiddleware(object): key = 'FixFirefoxMissingAJAXRedirectHeadersMiddleware' def process_request(self, request): if not request.is_ajax() and request.path == request.session.get(self.key, None): setattr(request, 'is_ajax', lambda: True) def process_response(self, request, response): if request.is_ajax() and 300 <= response.status_code < 400: request.session[self.key] = response['Location'] else: if self.key in request.session: del request.session[self.key] return response
More like this
- Effective content caching for mass-load site using redirect feature by nnseva 3 years, 10 months ago
- Ajax required decorator by zenx 7 years ago
- Middelware to remember sql query log from before a redirect by miracle2k 7 years, 8 months ago
- Cookieless Session Decorator by achimnol 5 years, 9 months ago
- Get boolean value from request send by Ajax by zalun 5 years, 11 months ago