From 53463b3fefc647952c4fa0dbf3b628845e08d6d2 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 16 Nov 2020 10:54:34 -0500 Subject: [PATCH] rpc: fix content-type header --- CHANGELOG.md | 23 +++++++++++++++++++++++ CHANGELOG_PENDING.md | 15 ++------------- rpc/jsonrpc/client/http_json_client.go | 23 +++++++++++++++++------ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a668bc3..9a8c1fc7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## v0.34.0-rc6 + +*November 5, 2020* + +Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermint). + +### IMPROVEMENTS + +- [statesync] \#5516 Check that all heights necessary to rebuild state for a snapshot exist before adding the snapshot to the pool. (@erikgrinaker) + +### BUG FIXES + +- [blockchain/v2] \#5499 Fix "duplicate block enqueued by processor" panic (@melekes) +- [abci/grpc] \#5520 Return async responses in order, to avoid mempool panics. (@erikgrinaker) +- [blockchain/v2] \#5530 Fix "processed height 4541 but expected height 4540" panic (@melekes) +- [consensus/wal] Fix WAL autorepair by opening target WAL in read/write mode (@erikgrinaker) +- [block] \#5567 Fix MaxCommitSigBytes (@cmwaters) +- [blockchain/v2] \#5553 Make the removal of an already removed peer a noop (@melekes) +- [evidence] \#5574 Fix bug where node sends committed evidence to peer (@cmwaters) +- [privval] \#5583 Make `Vote`, `Proposal` & `PubKey` non-nullable in Responses (@marbar3778) +- [evidence] \#5610 Make it possible for abci evidence to be formed from tm evidence (@cmwaters) +- [privval] \#5638 Increase read/write timeout to 5s and calculate ping interval based on it (@JoeKash) + ## v0.34.0-rc5 *October 13, 2020* diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 8fa12ab0b..78e78e56a 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -1,6 +1,6 @@ # Unreleased Changes -## v0.34.0-rc6 +## v0.34.0-rc7 Special thanks to external contributors on this release: @@ -22,17 +22,6 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi ### IMPROVEMENTS -- [statesync] \#5516 Check that all heights necessary to rebuild state for a snapshot exist before adding the snapshot to the pool. (@erikgrinaker) - ### BUG FIXES -- [blockchain/v2] \#5499 Fix "duplicate block enqueued by processor" panic (@melekes) -- [abci/grpc] \#5520 Return async responses in order, to avoid mempool panics. (@erikgrinaker) -- [blockchain/v2] \#5530 Fix "processed height 4541 but expected height 4540" panic (@melekes) -- [consensus/wal] Fix WAL autorepair by opening target WAL in read/write mode (@erikgrinaker) -- [block] \#5567 Fix MaxCommitSigBytes (@cmwaters) -- [blockchain/v2] \#5553 Make the removal of an already removed peer a noop (@melekes) -- [evidence] \#5574 Fix bug where node sends committed evidence to peer (@cmwaters) -- [privval] \#5583 Make `Vote`, `Proposal` & `PubKey` non-nullable in Responses (@marbar3778) -- [evidence] \#5610 Make it possible for abci evidence to be formed from tm evidence (@cmwaters) -- [privval] \#5638 Increase read/write timeout to 5s and calculate ping interval based on it (@JoeKash) +- [rpc] \#5660 Set `application/json` as the `Content-Type` header in RPC responses. diff --git a/rpc/jsonrpc/client/http_json_client.go b/rpc/jsonrpc/client/http_json_client.go index c6e1af035..59727390a 100644 --- a/rpc/jsonrpc/client/http_json_client.go +++ b/rpc/jsonrpc/client/http_json_client.go @@ -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)