Commit e922cceb authored by ibuler's avatar ibuler

[Update] 修改client

No related merge requests found
...@@ -22,6 +22,7 @@ type Client struct { ...@@ -22,6 +22,7 @@ type Client struct {
Timeout time.Duration Timeout time.Duration
Headers map[string]string Headers map[string]string
Auth ClientAuth Auth ClientAuth
basicAuth []string
cookie map[string]string cookie map[string]string
http *http.Client http *http.Client
UrlParsers []UrlParser UrlParsers []UrlParser
...@@ -47,6 +48,11 @@ func (c *Client) SetCookie(k, v string) { ...@@ -47,6 +48,11 @@ func (c *Client) SetCookie(k, v string) {
c.cookie[k] = v c.cookie[k] = v
} }
func (c *Client) SetBasicAuth(username, password string) {
c.basicAuth = append(c.basicAuth, username)
c.basicAuth = append(c.basicAuth, password)
}
func (c *Client) SetAuth(auth ClientAuth) { func (c *Client) SetAuth(auth ClientAuth) {
c.Auth = auth c.Auth = auth
} }
...@@ -86,6 +92,10 @@ func (c *Client) SetAuthHeader(r *http.Request, params ...map[string]string) { ...@@ -86,6 +92,10 @@ func (c *Client) SetAuthHeader(r *http.Request, params ...map[string]string) {
} }
r.Header.Add("Cookie", strings.Join(cookie, ";")) r.Header.Add("Cookie", strings.Join(cookie, ";"))
} }
if len(c.basicAuth) == 2 {
r.SetBasicAuth(c.basicAuth[0], c.basicAuth[1])
return
}
if c.Auth != nil { if c.Auth != nil {
r.Header.Set("Authorization", c.Auth.Sign()) r.Header.Set("Authorization", c.Auth.Sign())
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment