-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
request_url_user.go
53 lines (46 loc) · 1.24 KB
/
request_url_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package hit
import (
"net/url"
)
// IRequestURLUser provides methods to set the username and/or password for the request.
type IRequestURLUser interface {
// Username sets the username for the request.
Username(name string) IStep
// Password sets the password for the request.
Password(password string) IStep
}
type requestURLUser struct {
cleanPath callPath
}
func newRequestURLUser(clearPath callPath) IRequestURLUser {
return &requestURLUser{
cleanPath: clearPath,
}
}
func (v *requestURLUser) Username(name string) IStep {
return &hitStep{
Trace: ett.Prepare(),
When: requestCreateStep,
CallPath: v.cleanPath.Push("Username", []interface{}{name}),
Exec: func(hit *hitImpl) error {
password, ok := hit.request.URL.User.Password()
if ok {
hit.request.URL.User = url.UserPassword(name, password)
return nil
}
hit.request.URL.User = url.User(name)
return nil
},
}
}
func (v *requestURLUser) Password(password string) IStep {
return &hitStep{
Trace: ett.Prepare(),
When: requestCreateStep,
CallPath: v.cleanPath.Push("Password", []interface{}{password}),
Exec: func(hit *hitImpl) error {
hit.request.URL.User = url.UserPassword(hit.request.URL.User.Username(), password)
return nil
},
}
}