Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests v0.4.0 没有用递归实现redirect #13

Open
yuhanli1991 opened this issue Apr 11, 2018 · 1 comment
Open

requests v0.4.0 没有用递归实现redirect #13

yuhanli1991 opened this issue Apr 11, 2018 · 1 comment

Comments

@yuhanli1991
Copy link

def _build_response(self, resp):
        """Build internal Response object from given response."""

        def build(resp):
        	...

        history = []

        r = build(resp)

        if self.redirect:

            while 'location' in r.headers:

                history.append(r)

                url = r.headers['location']

                request = Request(
                    url, self.headers, self.files, self.method,
                    self.data, self.auth, self.cookiejar, redirect=False
                )
                request.send()
                r = request.response

            r.history = history

        self.response = r

这段代码并没有用到递归. 注意在Request实例化的时候参数redirect=False, 这意味着这个新建的实例并不会执行这段代码, 不会递归地进行redirect.

这里的redirect仅仅是使用一个while循环来不断转发的.

@ediwon23
Copy link

request.send() 里边 调用了 _build_response()自己

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants