- 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
- Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 6 months, 1 week ago
- Crispy Form by sourabhsinha396 7 months ago
- ReadOnlySelect by mkoistinen 7 months, 1 week ago
- Verify events sent to your webhook endpoints by santos22 8 months, 1 week ago
- Django Language Middleware by agusmakmun 8 months, 3 weeks ago