Skip to content

Commit

Permalink
feat: avoid clobbering original body for next read (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Mar 12, 2022
2 parents e1815d3 + 42acf34 commit ee0b0d5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion http2curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package http2curl
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -55,8 +56,10 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) {
var buff bytes.Buffer
_, err := buff.ReadFrom(req.Body)
if err != nil {
return nil, fmt.Errorf("getCurlCommand: buffer read from body erorr: %w", err)
return nil, fmt.Errorf("getCurlCommand: buffer read from body error: %w", err)
}
// reset body for potential re-reads
req.Body = ioutil.NopCloser(bytes.NewBuffer(buff.Bytes()))
if len(buff.String()) > 0 {
bodyEscaped := bashEscape(buff.String())
command.append("-d", bodyEscaped)
Expand All @@ -78,3 +81,4 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) {

return &command, nil
}

0 comments on commit ee0b0d5

Please sign in to comment.