Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Refactor request.postDataBuffer
Browse files Browse the repository at this point in the history
When the buffer is empty return a nil, which is how js apis work.
  • Loading branch information
ankur22 committed May 28, 2024
1 parent de142df commit 10a73ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 8 additions & 2 deletions browser/request_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ func mapRequest(vu moduleVU, r *common.Request) mapping {
}
return p
},
"postDataBuffer": r.PostDataBuffer,
"resourceType": r.ResourceType,
"postDataBuffer": func() any {
p := r.PostDataBuffer()
if len(p) == 0 {
return nil
}
return rt.NewArrayBuffer(p)
},
"resourceType": r.ResourceType,
"response": func(name string) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
resp := r.Response()
Expand Down
5 changes: 2 additions & 3 deletions common/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ func (r *Request) PostData() string {
}

// PostDataBuffer returns the request post data as an ArrayBuffer.
func (r *Request) PostDataBuffer() goja.ArrayBuffer {
rt := r.vu.Runtime()
return rt.NewArrayBuffer([]byte(r.postData))
func (r *Request) PostDataBuffer() []byte {
return []byte(r.postData)
}

// ResourceType returns the request resource type.
Expand Down

0 comments on commit 10a73ab

Please sign in to comment.