Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#12607 closed (invalid)

django.test.client.Client changes the HTTP method to "GET" when doing a redirect.

Reported by: pbiggar Owned by: nobody
Component: Testing framework Version: 1.2-alpha
Severity: Keywords: get redirect _handle_redirect
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

With the code:

Client().post(path, {}, follow=True)

where path causes a redirect, the HTTP verb will be changed to a GET. This is probably due to line 949 of http://code.djangoproject.com/svn/django/trunk/django/test/client.py. _handle_redirect is called from post(), put(), delete() etc, even though it redirects by calling get().

(My knowledge of HTTP is hazy, but it seems wrong to change this.)

Workaround: make sure tests dont redirect (which probably means avoid the automatic redirection of leaving a '/' off the end of paths).

I'm experiencing this with Django 1.1, but it looks like its still present in svn.

Change History (3)

comment:1 by Russell Keith-Magee, 15 years ago

Resolution: invalid
Status: newclosed

This is the intended behavior - the test client is doing exactly what a browser does. If you POST to a URL, and the POST returns a redirect, the browser doesn't POST the request to the redirected URL - it *always* uses GET for the redirected URL.

comment:2 by Alex Gaynor, 15 years ago

I just read through RFC2616 and you are correct that the spec says that you are supposed to redirect using the same request method, however the spec specifically notes that most clients transform any redirects into a GET, this is the behavior of most web browsers, AFAIK. I think the solution here might be for you to just use follow=False and do the redirect tracking manually, as I think the django test client wants to stay similar to browsers.

comment:3 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top