Skip to content

Commit

Permalink
decompress using gzip reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 committed Jun 24, 2024
1 parent ec815d8 commit 225ce84
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions code/go/0chain.net/validatorcore/storage/challenge_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"compress/gzip"
"context"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -66,9 +67,14 @@ func NewChallengeRequest(r *http.Request) (*ChallengeRequest, string, error) {
requestHash := r.Header.Get("X-App-Request-Hash")
h := sha3.New256()
tReader := io.TeeReader(r.Body, h)
var requestBody io.Reader
if strings.Contains(r.Header.Get("Content-Encoding"), "gzip") {
requestBody, _ = gzip.NewReader(tReader)
} else {
requestBody = tReader
}
var challengeRequest ChallengeRequest
decoder := json.NewDecoder(tReader)
err := decoder.Decode(&challengeRequest)
err := json.NewDecoder(requestBody).Decode(&challengeRequest)
if err != nil {
logging.Logger.Error("Error decoding the input to validator")
return nil, "", common.NewError("input_decode_error", "Error in decoding the input."+err.Error())
Expand Down

0 comments on commit 225ce84

Please sign in to comment.