Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit ac8746b

Browse files
jonasfranzlafriks
authored andcommitted
Add option for client with custom http client (#159)
1 parent a669487 commit ac8746b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

gitea/gitea.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func NewClient(url, token string) *Client {
3636
}
3737
}
3838

39+
// NewClientWithHTTP creates an API client with a custom http client
40+
func NewClientWithHTTP(url string, httpClient *http.Client) {
41+
client := NewClient(url, "")
42+
client.client = httpClient
43+
}
44+
3945
// SetHTTPClient replaces default http.Client with user given one.
4046
func (c *Client) SetHTTPClient(client *http.Client) {
4147
c.client = client
@@ -51,7 +57,9 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
5157
if err != nil {
5258
return nil, err
5359
}
54-
req.Header.Set("Authorization", "token "+c.accessToken)
60+
if len(c.accessToken) != 0 {
61+
req.Header.Set("Authorization", "token "+c.accessToken)
62+
}
5563
if c.sudo != "" {
5664
req.Header.Set("Sudo", c.sudo)
5765
}

0 commit comments

Comments
 (0)