mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-23 06:48:47 +00:00
Missing request body (#120)
* Never use harRequest.PostData.Params. Always use harRequest.PostData.Text. * Comment.
This commit is contained in:
parent
dc62195a8f
commit
fbf3d1729e
@ -1,9 +1,11 @@
|
||||
package tap
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -46,12 +48,27 @@ type HarFile struct {
|
||||
}
|
||||
|
||||
func NewEntry(request *http.Request, requestTime time.Time, response *http.Response, responseTime time.Time) (*har.Entry, error) {
|
||||
harRequest, err := har.NewRequest(request, true)
|
||||
harRequest, err := har.NewRequest(request, false)
|
||||
if err != nil {
|
||||
SilentError("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
|
||||
return nil, errors.New("Failed converting request to HAR")
|
||||
}
|
||||
|
||||
// For requests with multipart/form-data or application/x-www-form-urlencoded Content-Type,
|
||||
// martian/har will parse the request body and place the parameters in harRequest.PostData.Params
|
||||
// instead of harRequest.PostData.Text (as the HAR spec requires it).
|
||||
// Mizu currently only looks at PostData.Text. Therefore, instead of letting martian/har set the content of
|
||||
// PostData, always copy the request body to PostData.Text.
|
||||
if (request.ContentLength > 0) {
|
||||
reqBody, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
SilentError("read-request-body", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
|
||||
return nil, errors.New("Failed reading request body")
|
||||
}
|
||||
request.Body = ioutil.NopCloser(bytes.NewReader(reqBody))
|
||||
harRequest.PostData.Text = string(reqBody)
|
||||
}
|
||||
|
||||
harResponse, err := har.NewResponse(response, true)
|
||||
if err != nil {
|
||||
SilentError("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)
|
||||
|
Loading…
Reference in New Issue
Block a user