Skip to content

Commit

Permalink
Fix capture/runbook.go reading out request body
Browse files Browse the repository at this point in the history
Fix #342
  • Loading branch information
k1LoW committed Dec 5, 2022
1 parent 7de26d6 commit 21c9743
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
15 changes: 0 additions & 15 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,6 @@ func (rnr *httpRunner) Run(ctx context.Context, r *httpRequest) error {
if err := rnr.validator.ValidateRequest(ctx, req); err != nil {
return err
}
// reset Request.Body
reqBody, err := r.encodeBody()
if err != nil {
return err
}
rc, ok := reqBody.(io.ReadCloser)
if !ok && reqBody != nil {
rc = io.NopCloser(reqBody)
}
req.Body = rc

r.setContentTypeHeader(req)
for k, v := range r.headers {
req.Header.Set(k, v)
}

res, err = rnr.client.Do(req)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func CreateHTTPStepMapSlice(key string, req *http.Request) (yaml.MapSlice, error
{Key: contentType, Value: f},
}
case strings.Contains(contentType, MediaTypeMultipartFormData):
save, req.Body, err = drainBody(req.Body)
if err != nil {
return nil, fmt.Errorf("failed to drainBody: %w", err)
}

f := map[string]interface{}{}
mr, err := req.MultipartReader()
if err != nil {
Expand Down Expand Up @@ -131,6 +136,8 @@ func CreateHTTPStepMapSlice(key string, req *http.Request) (yaml.MapSlice, error
}
}
}
req.Body = save

bd = yaml.MapSlice{
{Key: MediaTypeMultipartFormData, Value: f},
}
Expand Down

0 comments on commit 21c9743

Please sign in to comment.