Skip to content

Commit

Permalink
Fix curl data option
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb9 committed Nov 9, 2022
1 parent 56fce48 commit f382307
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions transformers/httpie/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package httpie
import (
"encoding/json"
"errors"
"github.com/dcb9/curl2httpie/curl"
"github.com/dcb9/curl2httpie/httpie"
"io/ioutil"
"strings"

"github.com/dcb9/curl2httpie/curl"
"github.com/dcb9/curl2httpie/httpie"
)

type Transformer func(cl *httpie.CmdLine, o *curl.Option)
Expand Down Expand Up @@ -44,11 +45,18 @@ func Method(cl *httpie.CmdLine, o *curl.Option) {
var ErrUnknownDataType = errors.New("unknown data type")

func Data(cl *httpie.CmdLine, o *curl.Option) {
s := strings.SplitN(o.Arg, "=", 2)
if len(s) == 2 {
i := httpie.NewDataField(s[0], s[1])
cl.AddItem(i)
cl.HasBody = true
args := strings.Split(o.Arg, "&")
var urlEncoded bool
for _, arg := range args {
s := strings.SplitN(arg, "=", 2)
if len(s) == 2 {
i := httpie.NewDataField(s[0], s[1])
cl.AddItem(i)
cl.HasBody = true
urlEncoded = true
}
}
if urlEncoded {
return
}

Expand Down

0 comments on commit f382307

Please sign in to comment.