Skip to content

Commit

Permalink
fix: Avoid clobbering body so subsequent reads like middleware will n…
Browse files Browse the repository at this point in the history
…ot get nil

Signed-off-by: Steve Coffman <[email protected]>
  • Loading branch information
StevenACoffman committed Aug 25, 2021
1 parent 451764d commit 42acf34
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 @@ -37,8 +38,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 @@ -60,3 +63,4 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) {

return &command, nil
}

0 comments on commit 42acf34

Please sign in to comment.