Closed whalecold closed 3 years ago
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: To fully approve this pull request, please assign additional approvers. We suggest the following additional approver: supereagle
Assign the PR to them by writing /assign @supereagle
in a comment when ready.
The full list of commands accepted by this bot can be found here.
The pull request process is described here
这个现在就是支持的,rest config 里面有一个 Executor
配置项,这个就能 hack request,参考之前给 QA 写的设置认证的方式:
type requestExecutorWithAuth struct {
c *http.Client
username string
password string
}
// Do uses the http.Client to send an HTTP request and set basic authentication before sending.
func (r *requestExecutorWithAuth) Do(req *http.Request) (*http.Response, error) {
req.SetBasicAuth(r.username, r.password)
return r.c.Do(req)
}
// NewRequestExecutorWithAuth implements a custom nirvana rest.RequestExecutor to set authentication information on each request.
// Usage:
// xxx.NewClient(&rest.Config{
// Scheme: "...",
// Host: "...",
// Executor: NewRequestExecutorWithAuth("admin", "Pwd123456"),
// })
func NewRequestExecutorWithAuth(username, password string) rest.RequestExecutor {
return &requestExecutorWithAuth{
c: &http.Client{},
username: username,
password: password,
}
}
rest.NewClient(&rest.Config{
Scheme: "...",
Host: "...",
Executor: NewRequestExecutorWithAuth("admin", "xxx"),
})
/close
What this PR does / why we need it:
feat(hook): add hook function for http.request
Which issue(s) this PR is related to (optional, link to 3rd issue(s)):
Fixes #
Reference to #
Special notes for your reviewer:
/cc @iawia002
Release note: