Commit e922cceb authored by ibuler's avatar ibuler

[Update] 修改client

parent c9ebf9bd
......@@ -22,6 +22,7 @@ type Client struct {
Timeout time.Duration
Headers map[string]string
Auth ClientAuth
basicAuth []string
cookie map[string]string
http *http.Client
UrlParsers []UrlParser
......@@ -47,6 +48,11 @@ func (c *Client) SetCookie(k, v string) {
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) {
c.Auth = auth
}
......@@ -86,6 +92,10 @@ func (c *Client) SetAuthHeader(r *http.Request, params ...map[string]string) {
}
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 {
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