Skip to content

Commit

Permalink
Fix breaking change to work with PostDataEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Sep 27, 2024
1 parent 35faf56 commit affff35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
22 changes: 21 additions & 1 deletion common/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -104,13 +105,32 @@ func NewRequest(ctx context.Context, rp NewRequestParams) (*Request, error) {
isNavigationRequest := string(ev.RequestID) == string(ev.LoaderID) &&
ev.Type == network.ResourceTypeDocument

var pd string
for _, i := range ev.Request.PostDataEntries {
if i == nil {
continue
}

decodedBytes, err := base64.StdEncoding.DecodeString(i.Bytes)
if err != nil {
return nil, fmt.Errorf("decoding response body %q: %w", i.Bytes, err)
}

// TODO: Is this correct?
pd += string(decodedBytes)

fmt.Println(pd)
}

fmt.Println(pd)

r := Request{
url: u,
frame: rp.frame,
redirectChain: rp.redirectChain,
requestID: ev.RequestID,
method: ev.Request.Method,
postData: ev.Request.PostData,
postData: pd,
resourceType: ev.Type.String(),
isNavigationRequest: isNavigationRequest,
allowInterception: rp.allowInterception,
Expand Down
16 changes: 8 additions & 8 deletions common/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestRequest(t *testing.T) {
evt := &network.EventRequestWillBeSent{
RequestID: network.RequestID("1234"),
Request: &network.Request{
URL: "https://test/post",
Method: "POST",
Headers: network.Headers(headers),
PostData: "hello",
URL: "https://test/post",
Method: "POST",
Headers: network.Headers(headers),
PostDataEntries: []*network.PostDataEntry{{Bytes: "hello"}},
},
Timestamp: &ts,
WallTime: &wt,
Expand All @@ -42,10 +42,10 @@ func TestRequest(t *testing.T) {
evt := &network.EventRequestWillBeSent{
RequestID: network.RequestID("1234"),
Request: &network.Request{
URL: ":",
Method: "POST",
Headers: network.Headers(headers),
PostData: "hello",
URL: ":",
Method: "POST",
Headers: network.Headers(headers),
PostDataEntries: []*network.PostDataEntry{{Bytes: "hello"}},
},
Timestamp: &ts,
WallTime: &wt,
Expand Down

0 comments on commit affff35

Please sign in to comment.