Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module moul.io/http2curl/v2

go 1.13
go 1.16

require github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7 h1:+/+DxvQaYifJ+grD4klzrS5y+KJXldn/2YTl5JG+vZ8=
github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502 h1:34icjjmqJ2HPjrSuJYEkdZ+0ItmGQAQ75cRHIiftIyE=
github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8=
Expand Down Expand Up @@ -36,7 +33,5 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6 changes: 3 additions & 3 deletions http2curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package http2curl
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"sort"
"strings"
Expand All @@ -23,7 +23,7 @@ func (c *CurlCommand) String() string {
}

func bashEscape(str string) string {
return `'` + strings.Replace(str, `'`, `'\''`, -1) + `'`
return `'` + strings.ReplaceAll(str, `'`, `'\''`) + `'`
}

// GetCurlCommand returns a CurlCommand corresponding to an http.Request
Expand Down Expand Up @@ -59,7 +59,7 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) {
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()))
req.Body = io.NopCloser(bytes.NewBuffer(buff.Bytes()))
if len(buff.String()) > 0 {
bodyEscaped := bashEscape(buff.String())
command.append("-d", bodyEscaped)
Expand Down
8 changes: 4 additions & 4 deletions http2curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package http2curl
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -18,7 +18,7 @@ func ExampleGetCurlCommand() {
form.Add("name", "Hudson")
body := form.Encode()

req, _ := http.NewRequest(http.MethodPost, "http://foo.com/cats", ioutil.NopCloser(bytes.NewBufferString(body)))
req, _ := http.NewRequest(http.MethodPost, "http://foo.com/cats", io.NopCloser(bytes.NewBufferString(body)))
req.Header.Set("API_KEY", "123")

command, _ := GetCurlCommand(req)
Expand Down Expand Up @@ -149,7 +149,7 @@ func BenchmarkGetCurlCommand(b *testing.B) {
for i := 0; i <= b.N; i++ {
form.Add("number", strconv.Itoa(i))
body := form.Encode()
req, _ := http.NewRequest(http.MethodPost, "http://foo.com", ioutil.NopCloser(bytes.NewBufferString(body)))
req, _ := http.NewRequest(http.MethodPost, "http://foo.com", io.NopCloser(bytes.NewBufferString(body)))
_, err := GetCurlCommand(req)
if err != nil {
panic(err)
Expand All @@ -172,7 +172,7 @@ func TestGetCurlCommand_serverSide(t *testing.T) {
t.Error(err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err)
}
Expand Down