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

grequests how to disable Redirect #72

Open
Wd0g opened this issue Dec 4, 2018 · 3 comments
Open

grequests how to disable Redirect #72

Wd0g opened this issue Dec 4, 2018 · 3 comments

Comments

@Wd0g
Copy link

Wd0g commented Dec 4, 2018

I thought it would be like this.

grequests.RequestOptions{
	RedirectLimit: -1,
}

But this code does not disable redirect,please tell me how to disable redirect, thanks~~~

@Wd0g
Copy link
Author

Wd0g commented Dec 4, 2018

maybe have some simple code to disable redirect?

@Wd0g
Copy link
Author

Wd0g commented Dec 4, 2018

utils.go

func addRedirectFunctionality(client *http.Client, ro *RequestOptions) {
	if client.CheckRedirect != nil {
		return
	}
	client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
                // here is new code
		if ro.RedirectLimit == -1{
			return http.ErrUseLastResponse
		}
                //over

		if ro.RedirectLimit == 0 {
			ro.RedirectLimit = RedirectLimit
		}

		if len(via) >= ro.RedirectLimit {
			return ErrRedirectLimitExceeded
		}

		if ro.SensitiveHTTPHeaders == nil {
			ro.SensitiveHTTPHeaders = SensitiveHTTPHeaders
		}

		for k, vv := range via[0].Header {
			// Is this a sensitive header?
			if _, found := ro.SensitiveHTTPHeaders[k]; found {
				continue
			}

			for _, v := range vv {
				req.Header.Add(k, v)
			}
		}

		return nil
	}
}

@ehmo
Copy link
Contributor

ehmo commented Jan 23, 2019

I actually just found out that you posted this issue. I created a pull request #75 that fixes this. Hopefully @levigross will see it the same way.

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