NewHttpRequest constructs a new HTTP request and injects provider credentials into it.
(ctx context.Context, auth *Auth, method, targetURL string, body []byte, headers http.Header)
| 5776 | |
| 5777 | // NewHttpRequest constructs a new HTTP request and injects provider credentials into it. |
| 5778 | func (m *Manager) NewHttpRequest(ctx context.Context, auth *Auth, method, targetURL string, body []byte, headers http.Header) (*http.Request, error) { |
| 5779 | if ctx == nil { |
| 5780 | ctx = context.Background() |
| 5781 | } |
| 5782 | method = strings.TrimSpace(method) |
| 5783 | if method == "" { |
| 5784 | method = http.MethodGet |
| 5785 | } |
| 5786 | var reader io.Reader |
| 5787 | if body != nil { |
| 5788 | reader = bytes.NewReader(body) |
| 5789 | } |
| 5790 | httpReq, err := http.NewRequestWithContext(ctx, method, targetURL, reader) |
| 5791 | if err != nil { |
| 5792 | return nil, err |
| 5793 | } |
| 5794 | if headers != nil { |
| 5795 | httpReq.Header = headers.Clone() |
| 5796 | } |
| 5797 | if errPrepare := m.PrepareHttpRequest(ctx, auth, httpReq); errPrepare != nil { |
| 5798 | return nil, errPrepare |
| 5799 | } |
| 5800 | return httpReq, nil |
| 5801 | } |
| 5802 | |
| 5803 | // HttpRequest injects provider credentials into the supplied HTTP request and executes it. |
| 5804 | func (m *Manager) HttpRequest(ctx context.Context, auth *Auth, req *http.Request) (*http.Response, error) { |
no test coverage detected