Skip to content

Commit f64a39e

Browse files
committed
Merge pull request #8 from lewispeckover/master
Allow sending request data from a file or stdin
2 parents 4b886f6 + 17030fa commit f64a39e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

unixhttp.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"io"
7+
"io/ioutil"
78
"net"
89
"net/http"
910
"net/http/httputil"
@@ -69,6 +70,24 @@ func main() {
6970
if method == "GET" {
7071
method = "POST"
7172
}
73+
// If data begins with @, it references a file
74+
if (string(data[0]) == "@" && len(data) > 1) {
75+
if (string(data[1:]) == "-") {
76+
buf, err := ioutil.ReadAll(os.Stdin)
77+
if (err != nil) {
78+
fmt.Println("Failed to read from stdin:", err)
79+
os.Exit(1)
80+
}
81+
reader = strings.NewReader(string(buf))
82+
} else {
83+
buf, err := ioutil.ReadFile(string(data[1:]))
84+
if (err != nil) {
85+
fmt.Println("Failed to open file:", err)
86+
os.Exit(1)
87+
}
88+
reader = strings.NewReader(string(buf))
89+
}
90+
}
7291
}
7392

7493
query := ""

0 commit comments

Comments
 (0)