Skip to content

Commit

Permalink
fix(#37): header copy in redirect plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Oct 13, 2017
1 parent f37ccc1 commit 0bd1aac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions _examples/redirect/redirect.go
Expand Up @@ -11,11 +11,14 @@ func main() {
// Create a new client
cli := gentleman.New()

// Set authorization header
cli.SetHeader("Authorization", "s3cr3t!")

// Define the maximum number of redirects
cli.Use(redirect.Limit(20))
cli.Use(redirect.Limit(10))

// Perform the request
res, err := cli.Request().URL("http://httpbin.org/headers").Send()
res, err := cli.Request().URL("http://httpbin.org/relative-redirect/3").Send()
if err != nil {
fmt.Printf("Request error: %s\n", err)
return
Expand Down
9 changes: 4 additions & 5 deletions plugins/redirect/redirect.go
Expand Up @@ -2,10 +2,11 @@ package redirect

import (
"errors"
c "gopkg.in/h2non/gentleman.v2/context"
p "gopkg.in/h2non/gentleman.v2/plugin"
"net/http"
"strings"

c "gopkg.in/h2non/gentleman.v2/context"
p "gopkg.in/h2non/gentleman.v2/plugin"
)

var (
Expand Down Expand Up @@ -92,7 +93,5 @@ func copyHeaders(k string, vv []string, opts Options, req *http.Request) {
}
}

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

0 comments on commit 0bd1aac

Please sign in to comment.