1
0
mirror of https://github.com/fiatjaf/nak.git synced 2025-08-13 06:20:47 -04:00

curl: assume POST when there is data and no method is specified.

This commit is contained in:
fiatjaf
2025-02-05 10:37:15 -03:00
parent 4392293ed6
commit d00976a669

30
curl.go

@@ -28,7 +28,22 @@ var curl = &cli.Command{
// cowboy parsing of curl flags to get the data we need for nip98
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
for _, f := range curlFlags {
@@ -42,6 +57,11 @@ var curl = &cli.Command{
} else if f == "--request" || f == "-X" {
nextIsMethod = true
continue
} else if slices.Contains(curlBodyBuildingFlags, f) ||
slices.ContainsFunc(curlBodyBuildingFlags, func(s string) bool {
return strings.HasPrefix(f, s)
}) {
presumedMethod = "POST"
}
nextIsMethod = false
}
@@ -50,6 +70,14 @@ var curl = &cli.Command{
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
evt := nostr.Event{
Kind: 27235,