Skip to content

Commit

Permalink
feat(httereq): support authorization bearer
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuigo committed Jul 15, 2024
1 parent 88c856b commit 4844fb0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/httpreq/curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestCurl(t *testing.T) {
AddCookieKV("count", "1").
AddFileHeader("file", "test.txt", []byte("hello world")).
AddFileHeader("file2", "test.txt", []byte("hello world2")).
SetReq("GET", "/path").
ToCurl()
if err != nil {
t.Fatal(err)
Expand Down
8 changes: 7 additions & 1 deletion httpreq/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (r *request) SetAuthBasic(username, password string) *request {
return r
}

func (r *request) SetAuthBearer(token string) *request {
r.rawreq.Header.Set("Authorization", "Bearer "+token)
return r
}

func (r *request) AddCookies(cookies []*http.Cookie) *request {
for _, cookie := range cookies {
r.rawreq.AddCookie(cookie)
Expand Down Expand Up @@ -99,8 +104,9 @@ func (r *request) SetUrl(url string) *request {
return r
}

func (r *request) SetMethod(method string) *request {
func (r *request) SetReq(method string, url string) *request {
r.rawreq.Method = method
r.url = url
return r
}

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.3
v0.0.4

0 comments on commit 4844fb0

Please sign in to comment.