Skip to content

Commit

Permalink
ghttp
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Dec 20, 2023
1 parent d1ab916 commit 677b7f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion util/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ func TestHTTPClient_Get6(t *testing.T) {
assert := assert2.New(t)
client := NewHTTPClient()
client.SetClientCert(cert, key)
body, _, _, _ := client.Get(httpsServerURL2+"/hello", time.Second, nil, map[string]string{"token": "200"})
body, _, resp, _ := client.Get(httpsServerURL2+"/hello", time.Second, nil, map[string]string{"token": "200"})
assert.Contains(string(body), "hello")
assert.Contains(string(GetResponseBody(resp)), "hello")
}

func TestHTTPClient_SetProxyFromEnv(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions util/http/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ func GetResponseBody(resp *http.Response) []byte {
b, _ := GetResponseBodyE(resp)
return b
}

func GetContent(_url string, timeout time.Duration) []byte {
d, _ := GetContentE(_url, timeout)
return d
}

func GetContentE(_url string, timeout time.Duration) ([]byte, error) {
d, _, e := Download(_url, timeout, nil, nil)
return d, e
}
13 changes: 13 additions & 0 deletions util/http/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ghttp

import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestGetContents(t *testing.T) {
assert.Equal(t, "hello", string(GetContent(httpServerURL+"/hello", time.Second)))
_, e := GetContentE("http://none/none", time.Second)
assert.NotNil(t, e)
}

0 comments on commit 677b7f2

Please sign in to comment.