O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The Client of the http package contains the CheckRedirect field. The field is a function that has the req and via parameters. req is the upcoming request and via refers to the previous requests. This way, you can modify the request after the redirect. In the previous example, the Known-redirects header is modified.

In case the CheckRedirect function returns the error, the last response with a closed body accompanied with a wrapped error is returned. In case the http.ErrUseLastResponse is returned, the last response is returned, but the body is not closed so it is possible to read it.

By default, the CheckRedirect property is nil. In this case, it has a limit of 10 redirects. After this count, redirecting is stopped.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required