From 4844fb0678f5db6caa304923c59cb2ea147dc23e Mon Sep 17 00:00:00 2001 From: ahuigo <1781999+ahuigo@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:55:55 +0800 Subject: [PATCH] feat(httereq): support authorization bearer --- demo/httpreq/curl_test.go | 1 + httpreq/req.go | 8 +++++++- version | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/demo/httpreq/curl_test.go b/demo/httpreq/curl_test.go index 0fb7b13..8498c0c 100644 --- a/demo/httpreq/curl_test.go +++ b/demo/httpreq/curl_test.go @@ -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) diff --git a/httpreq/req.go b/httpreq/req.go index 15167df..0fbd59c 100644 --- a/httpreq/req.go +++ b/httpreq/req.go @@ -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) @@ -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 } diff --git a/version b/version index 8ce995b..a92e827 100644 --- a/version +++ b/version @@ -1 +1 @@ -v0.0.3 \ No newline at end of file +v0.0.4 \ No newline at end of file