February 2018
Intermediate to advanced
340 pages
9h 43m
English
package main import ( "fmt" "net/http" ) const addr = "localhost:7070" type RedirecServer struct { redirectCount int } func (s *RedirecServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { s.redirectCount++ fmt.Println("Received header: " + req.Header.Get("Known-redirects")) http.Redirect(rw, req, fmt.Sprintf("/redirect%d", s.redirectCount), http.StatusTemporaryRedirect) } func main() { s := http.Server{ Addr: addr, Handler: &RedirecServer{0}, } go s.ListenAndServe() client := http.Client{} redirectCount := 0 // If the count of redirects is reached // than return error. ...Read now
Unlock full access