pkg/tool/http: make request.body optional
For simple GET requests this is quite weird to have to set:
`request: body: ""`
Change-Id: I41a86ba5a5ab2dd25dad792e2efa4b95b874e30f
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9722
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/pkg/tool/http/doc.go b/pkg/tool/http/doc.go
index 01c33b3..9941311 100644
--- a/pkg/tool/http/doc.go
+++ b/pkg/tool/http/doc.go
@@ -16,7 +16,7 @@
// url: string // TODO: make url.URL type
//
// request: {
-// body: *bytes | string
+// body?: bytes | string
// header: [string]: string | [...string]
// trailer: [string]: string | [...string]
// }
diff --git a/pkg/tool/http/http.cue b/pkg/tool/http/http.cue
index 0ab1dd5..1526561 100644
--- a/pkg/tool/http/http.cue
+++ b/pkg/tool/http/http.cue
@@ -26,7 +26,7 @@
url: string // TODO: make url.URL type
request: {
- body: *bytes | string
+ body?: bytes | string
header: [string]: string | [...string]
trailer: [string]: string | [...string]
}
diff --git a/pkg/tool/http/http.go b/pkg/tool/http/http.go
index fa55264..e6651be 100644
--- a/pkg/tool/http/http.go
+++ b/pkg/tool/http/http.go
@@ -18,6 +18,7 @@
//go:generate gofmt -s -w .
import (
+ "bytes"
"io"
"io/ioutil"
"net/http"
@@ -52,6 +53,8 @@
if err != nil {
return nil, err
}
+ } else {
+ r = bytes.NewReader([]byte(""))
}
if header, err = parseHeaders(obj, "header"); err != nil {
return nil, err
diff --git a/pkg/tool/http/pkg.go b/pkg/tool/http/pkg.go
index d211080..e1683eb 100644
--- a/pkg/tool/http/pkg.go
+++ b/pkg/tool/http/pkg.go
@@ -36,7 +36,7 @@
method: string
url: string
request: {
- body: *bytes | string
+ body?: bytes | string
header: {
[string]: string | [...string]
}