1. Armin Ronacher
  2. werkzeug-main

Commits

EnTeQuAk  committed 22a7d99

Added follow_redirect to the werkzeug.test.Client for easier testing.

  • Participants
  • Parent commits 68b88b8
  • Branches default

Comments (0)

Files changed (15)

File examples/cupoftee/shared/down.png

  • Ignore whitespace
Old
Old image
New
New image

File examples/cupoftee/shared/up.png

  • Ignore whitespace
Old
Old image
New
New image

File examples/manage-coolmagic.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-couchy.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-cupoftee.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-i18nurls.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-plnt.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-shorty.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-simplewiki.py

  • Ignore whitespace
File contents unchanged.

File examples/manage-webpylike.py

  • Ignore whitespace
File contents unchanged.

File werkzeug/debug/shared/console.png

  • Ignore whitespace
Old
Old image
New
New image

File werkzeug/debug/shared/less.png

  • Ignore whitespace
Old
Old image
New
New image

File werkzeug/debug/shared/more.png

  • Ignore whitespace
Old
Old image
New
New image

File werkzeug/debug/shared/source.png

  • Ignore whitespace
Old
Old image
New
New image

File werkzeug/test.py

View file
  • Ignore whitespace
         Additional parameters:
 
         :param as_tuple: Returns a tuple in the form ``(environ, result)``
-        :param buffered: set this to true to buffer the application run.
+        :param buffered: Set this to true to buffer the application run.
                          This will automatically close the application for
                          you as well.
+        :param follow_redirects: Set this to false if the `Client` should not
+                                 follow http redirects.
         """
         as_tuple = kwargs.pop('as_tuple', False)
         buffered = kwargs.pop('buffered', False)
+        follow_redirects = kwargs.pop('follow_redirects', True)
         environ = None
         if not kwargs and len(args) == 1:
             if isinstance(args[0], EnvironBuilder):
         rv = run_wsgi_app(self.application, environ, buffered=buffered)
         if self.cookie_jar is not None:
             self.cookie_jar.extract_wsgi(environ, rv[2])
+
+        if rv[0].status_code in (301, 302, 303, 305, 307) and follow_redirects:
+            redirect = urlparse.urlunsplit(urlparse.urlsplit(
+                dict(rv[2])['Location'])[:-2] + ('', ''))
+            kwargs.update({
+                'base_url': redirect,
+                'as_tuple': as_tuple,
+                'buffered': buffered,
+                'follow_redirects': follow_redirects,
+            })
+            return self.open(*args, **kwargs)
+
         response = self.response_wrapper(*rv)
         if as_tuple:
             return environ, response