Web3signer: Support json content type with optional metadata (#11058)

* initial commit

* wanting to trigger ci
This commit is contained in:
james-prysm 2022-07-15 12:01:54 -04:00 committed by GitHub
parent e2442bb0a6
commit a775798d89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import (
"net/http/httputil"
"net/url"
"strconv"
"strings"
"time"
"github.com/ethereum/go-ethereum/common/hexutil"
@ -74,14 +75,13 @@ func (client *ApiClient) Sign(ctx context.Context, pubKey string, request SignRe
return nil, fmt.Errorf("signing operation failed due to slashing protection rules, Signing Request URL: %v, Status: %v", client.BaseURL.String()+requestPath, resp.StatusCode)
}
contentType := resp.Header.Get("Content-Type")
switch contentType {
case "application/json":
if strings.HasPrefix(contentType, "application/json") {
var sigResp SignatureResponse
if err := unmarshalResponse(resp.Body, &sigResp); err != nil {
return nil, err
}
return bls.SignatureFromBytes(sigResp.Signature)
default:
} else {
return unmarshalSignatureResponse(resp.Body)
}
}

View File

@ -59,10 +59,10 @@ func TestClient_Sign_HappyPath_Jsontype(t *testing.T) {
}
jsonBytes, err := json.Marshal(sigResp)
require.NoError(t, err)
require.NoError(t, err)
// create a new reader with that JSON
header := http.Header{
"Content-Type": []string{"application/json"},
}
header := http.Header{}
header.Set("Content-Type", "application/json; charset=UTF-8")
r := io.NopCloser(bytes.NewReader(jsonBytes))
mock := &mockTransport{mockResponse: &http.Response{
StatusCode: 200,