diff --git a/client.go b/client.go index 520088c..d827f6e 100644 --- a/client.go +++ b/client.go @@ -69,23 +69,15 @@ func (c *Client) Do(ctx context.Context, method, pathOrURL string, body, receive if strings.HasPrefix(pathOrURL, "jsonhttpc.Parse error: ") { return errors.New(pathOrURL) } - // prepare the request. if ctx == nil { ctx = context.Background() } - u, err := c.parseURL(pathOrURL) - if err != nil { - return err - } - r, err := c.bodyReader(body) - if err != nil { - return err - } - req, err := http.NewRequestWithContext(ctx, method, u.String(), r) + + // prepare the request. + req, err := c.newRawRequest(ctx, method, pathOrURL, body) if err != nil { return err } - c.setupHeader(req, body) // make messages round trip. c.logReq(ctx, req) @@ -124,6 +116,23 @@ func (c *Client) Do(ctx context.Context, method, pathOrURL string, body, receive return nil } +func (c *Client) newRawRequest(ctx context.Context, method, pathOrURL string, body any) (*http.Request, error) { + u, err := c.parseURL(pathOrURL) + if err != nil { + return nil, err + } + r, err := c.bodyReader(body) + if err != nil { + return nil, err + } + req, err := http.NewRequestWithContext(ctx, method, u.String(), r) + if err != nil { + return nil, err + } + c.setupHeader(req, body) + return req, nil +} + func (c *Client) parseURL(pathOrURL string) (*url.URL, error) { if c.u != nil { return c.u.Parse(pathOrURL) diff --git a/path.go b/path.go index 3b1790a..6707b22 100644 --- a/path.go +++ b/path.go @@ -16,7 +16,7 @@ type Params map[string]interface{} // '\' escapes a rune succeeding. // // This returns a string with prefix "jsonhttpc.Parse error: " if detects some -// errors, +// errors. func Path(s string, p Params) string { s2, err := path(s, p) if err != nil {