mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-09 00:58:50 +00:00
curl: assume POST when there is data and no method is specified.
This commit is contained in:
30
curl.go
30
curl.go
@@ -28,7 +28,22 @@ var curl = &cli.Command{
|
|||||||
|
|
||||||
// cowboy parsing of curl flags to get the data we need for nip98
|
// cowboy parsing of curl flags to get the data we need for nip98
|
||||||
var url string
|
var url string
|
||||||
method := "GET"
|
var method string
|
||||||
|
var presumedMethod string
|
||||||
|
|
||||||
|
curlBodyBuildingFlags := []string{
|
||||||
|
"-d",
|
||||||
|
"--data",
|
||||||
|
"--data-binary",
|
||||||
|
"--data-ascii",
|
||||||
|
"--data-raw",
|
||||||
|
"--data-urlencode",
|
||||||
|
"-F",
|
||||||
|
"--form",
|
||||||
|
"--form-string",
|
||||||
|
"--form-escape",
|
||||||
|
"--upload-file",
|
||||||
|
}
|
||||||
|
|
||||||
nextIsMethod := false
|
nextIsMethod := false
|
||||||
for _, f := range curlFlags {
|
for _, f := range curlFlags {
|
||||||
@@ -42,6 +57,11 @@ var curl = &cli.Command{
|
|||||||
} else if f == "--request" || f == "-X" {
|
} else if f == "--request" || f == "-X" {
|
||||||
nextIsMethod = true
|
nextIsMethod = true
|
||||||
continue
|
continue
|
||||||
|
} else if slices.Contains(curlBodyBuildingFlags, f) ||
|
||||||
|
slices.ContainsFunc(curlBodyBuildingFlags, func(s string) bool {
|
||||||
|
return strings.HasPrefix(f, s)
|
||||||
|
}) {
|
||||||
|
presumedMethod = "POST"
|
||||||
}
|
}
|
||||||
nextIsMethod = false
|
nextIsMethod = false
|
||||||
}
|
}
|
||||||
@@ -50,6 +70,14 @@ var curl = &cli.Command{
|
|||||||
return fmt.Errorf("can't create nip98 event: target url is empty")
|
return fmt.Errorf("can't create nip98 event: target url is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if method == "" {
|
||||||
|
if presumedMethod != "" {
|
||||||
|
method = presumedMethod
|
||||||
|
} else {
|
||||||
|
method = "GET"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// make and sign event
|
// make and sign event
|
||||||
evt := nostr.Event{
|
evt := nostr.Event{
|
||||||
Kind: 27235,
|
Kind: 27235,
|
||||||
|
|||||||
Reference in New Issue
Block a user