Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
64787c7cb0 | |||
b68c93e092 | |||
767b660a22 | |||
6142a1100c |
30
request.go
30
request.go
@ -121,7 +121,7 @@ func Method(method string) RequestModifier {
|
||||
}
|
||||
}
|
||||
|
||||
func Headers(keyValuePairs ...string) RequestModifier {
|
||||
func AddHeaders(keyValuePairs ...string) RequestModifier {
|
||||
if len(keyValuePairs)%2 != 0 {
|
||||
panic("keyValuePairs must have an even length")
|
||||
}
|
||||
@ -143,7 +143,21 @@ func RemoveHeaders(headers ...string) RequestModifier {
|
||||
}
|
||||
}
|
||||
|
||||
func HeadersMap(headers map[string]string) RequestModifier {
|
||||
func RemoveAllHeaders() RequestModifier {
|
||||
return func(r *RequestBuilder) *RequestBuilder {
|
||||
r.Header = make(http.Header)
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
func Headers(keyValuePairs ...string) RequestModifier {
|
||||
return chainMods(
|
||||
RemoveAllHeaders(),
|
||||
AddHeaders(keyValuePairs...),
|
||||
)
|
||||
}
|
||||
|
||||
func AddHeadersMap(headers map[string]string) RequestModifier {
|
||||
return func(r *RequestBuilder) *RequestBuilder {
|
||||
for key, value := range headers {
|
||||
r.Header.Add(key, value)
|
||||
@ -152,8 +166,18 @@ func HeadersMap(headers map[string]string) RequestModifier {
|
||||
}
|
||||
}
|
||||
|
||||
func HeadersMap(headers map[string]string) RequestModifier {
|
||||
return chainMods(
|
||||
RemoveAllHeaders(),
|
||||
AddHeadersMap(headers),
|
||||
)
|
||||
}
|
||||
|
||||
func Auth(auth AuthProvider) RequestModifier {
|
||||
return Headers("Authentication", auth())
|
||||
return chainMods(
|
||||
RemoveHeaders("Authorization"),
|
||||
AddHeaders("Authorization", auth()),
|
||||
)
|
||||
}
|
||||
|
||||
func Basic(username, password string) AuthProvider {
|
||||
|
Loading…
x
Reference in New Issue
Block a user