Browse Source

rpc: fix content-type header (#5661)

pull/5663/head
Aleksandr Bezobchuk 4 years ago
committed by GitHub
parent
commit
8aa47c7da5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions
  1. +2
    -2
      CHANGELOG_PENDING.md
  2. +17
    -6
      rpc/jsonrpc/client/http_json_client.go

+ 2
- 2
CHANGELOG_PENDING.md View File

@ -9,8 +9,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
### BREAKING CHANGES
- CLI/RPC/Config
- [config] \#5598 The `test_fuzz` and `test_fuzz_config` P2P settings have been removed. (@erikgrinaker)
- [config] \#5598 The `test_fuzz` and `test_fuzz_config` P2P settings have been removed. (@erikgrinaker)
- Apps
@ -31,5 +30,6 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
### BUG FIXES
- [rpc] \#5660 Set `application/json` as the `Content-Type` header in RPC responses.
- [types] \#5523 Change json naming of `PartSetHeader` within `BlockID` from `parts` to `part_set_header` (@marbar3778)
- [privval] \#5638 Increase read/write timeout to 5s and calculate ping interval based on it (@JoeKash)

+ 17
- 6
rpc/jsonrpc/client/http_json_client.go View File

@ -151,10 +151,13 @@ func NewWithHTTPClient(remote string, client *http.Client) (*Client, error) {
}
// Call issues a POST HTTP request. Requests are JSON encoded. Content-Type:
// text/json.
func (c *Client) Call(ctx context.Context, method string,
params map[string]interface{}, result interface{}) (interface{}, error) {
// application/json.
func (c *Client) Call(
ctx context.Context,
method string,
params map[string]interface{},
result interface{},
) (interface{}, error) {
id := c.nextRequestID()
request, err := types.MapToRequest(id, method, params)
@ -172,14 +175,18 @@ func (c *Client) Call(ctx context.Context, method string,
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
httpRequest.Header.Set("Content-Type", "text/json")
httpRequest.Header.Set("Content-Type", "application/json")
if c.username != "" || c.password != "" {
httpRequest.SetBasicAuth(c.username, c.password)
}
httpResponse, err := c.client.Do(httpRequest)
if err != nil {
return nil, fmt.Errorf("post failed: %w", err)
}
defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)
@ -216,14 +223,18 @@ func (c *Client) sendBatch(ctx context.Context, requests []*jsonRPCBufferedReque
if err != nil {
return nil, fmt.Errorf("new request: %w", err)
}
httpRequest.Header.Set("Content-Type", "text/json")
httpRequest.Header.Set("Content-Type", "application/json")
if c.username != "" || c.password != "" {
httpRequest.SetBasicAuth(c.username, c.password)
}
httpResponse, err := c.client.Do(httpRequest)
if err != nil {
return nil, fmt.Errorf("post: %w", err)
}
defer httpResponse.Body.Close()
responseBytes, err := ioutil.ReadAll(httpResponse.Body)


Loading…
Cancel
Save