File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -436,6 +436,11 @@ func (cli *CLIArgs) GetHTTPRequest() (*httprequest.HTTPRequest, error) {
436
436
var url string
437
437
438
438
url = cli .buildURL ()
439
+ var stat os.FileInfo
440
+ var staterr error
441
+ if os .Stdin != nil {
442
+ stat , staterr = os .Stdin .Stat ()
443
+ }
439
444
440
445
// TODO: is command == "" required?
441
446
if ! cli .IsHelp && (cli .Command == AddCommand ||
@@ -445,8 +450,10 @@ func (cli *CLIArgs) GetHTTPRequest() (*httprequest.HTTPRequest, error) {
445
450
url0 , body0 := cli .buildSingleParamBody ()
446
451
url += url0
447
452
body = body0
448
- } else {
449
- // if there is text on the standard input that'll used as the body
453
+ } else if os .Stdin != nil && staterr == nil &&
454
+ stat .Mode () & os .ModeCharDevice == 0 && stat .Size () > 0 {
455
+ // os.ModeCharDevice flag is set when piping text to the stdin
456
+ // use text in the standard input as body
450
457
var buffer bytes.Buffer
451
458
reader := bufio .NewReader (os .Stdin )
452
459
text , _ := reader .ReadString ('\n' )
@@ -465,6 +472,8 @@ func (cli *CLIArgs) GetHTTPRequest() (*httprequest.HTTPRequest, error) {
465
472
} else {
466
473
body = cli .buildBody ()
467
474
}
475
+ } else {
476
+ body = cli .buildBody ()
468
477
}
469
478
}
470
479
You can’t perform that action at this time.
0 commit comments