Skip to content

Commit

Permalink
Merge branch 'release/11.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSLevy committed Apr 18, 2019
2 parents 7d987d5 + 498c9dc commit e596adc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 15 additions & 4 deletions client.go
Expand Up @@ -18,6 +18,7 @@ type Client struct {
BasicAuth bool
User string
Password string
Header http.Header
}

// Request uses c to make a JSON-RPC 2.0 Request to url with the given method
Expand All @@ -31,8 +32,13 @@ type Client struct {
//
// Request uses a pseudorandom uint32 for the Request.ID.
//
// If c.BasicAuth is true then SetBasicAuth will be called on the http.Request
// using c.User and c.Password.
// Requests will have the "Content-Type":"application/json" header added.
//
// Any populated c.Header will then be added to the http.Request, so you may
// override the "Content-Type" header with your own.
//
// If c.BasicAuth is true then http.Request.SetBasicAuth(c.User, c.Password)
// will be called. This will override the same header in c.Header.
//
// If c.DebugRequest is true then the Request and Response will be printed to
// stdout.
Expand All @@ -50,15 +56,20 @@ func (c *Client) Request(url, method string, params, result interface{}) error {
return err
}

// Make the HTTP request.
// Compose the HTTP request.
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(reqBytes))
if err != nil {
return err
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add(http.CanonicalHeaderKey("Content-Type"), "application/json")
for k, v := range c.Header {
req.Header[http.CanonicalHeaderKey(k)] = v
}
if c.BasicAuth {
req.SetBasicAuth(c.User, c.Password)
}

// Make the request.
res, err := c.Do(req)
if err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions methods.go
Expand Up @@ -32,11 +32,13 @@ type MethodMap map[string]MethodFunc
//
// A valid MethodFunc must return a not-nil interface{} that will not cause an
// error when passed to json.Marshal. If the underlying type of the returned
// interface{} is Error, then an Error Response will be returned to the client.
// Any return value that is not an Error will be used as the "result" field.
// interface{} is Error or *Error, then an Error Response will be returned to
// the client. If the underlying type of the returned interface{} is any other
// generic error, than an Internal Error will be returned to the client. Any
// return value that is not an error will be used as the "result" field.
//
// If the MethodFunc returns an Error, then the Error must either use the
// InvalidParamsCode, or it must use an Error.Code that is outside of the
// If the MethodFunc returns an Error or *Error, then the Error must either use
// the InvalidParamsCode, or it must use an Error.Code that is outside of the
// reserved error code range. See ErrorCode.IsReserved() for more information.
//
// An invalid MethodFunc will result in an Internal Error to be returned to the
Expand Down

0 comments on commit e596adc

Please sign in to comment.