Skip to content

Commit

Permalink
Pass request body data to STDIN for PUT, PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Skrach committed Jul 31, 2019
1 parent 4eeac27 commit 0a22a21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Usage
-form : parse query into environment vars, handle uploaded files
-cgi : run scripts in CGI-mode:
- set environment variables with HTTP-request information
- write POST-data to script STDIN (if is not set -form)
- write POST|PUT|PATCH-data to script STDIN (if is not set -form)
- parse headers from script (eg: "Location: URL\n\n")
-export-vars=var: export environment vars ("VAR1,VAR2,...")
by default export PATH, HOME, LANG, USER, TMPDIR
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Usage:
-form : parse query into environment vars, handle uploaded files
-cgi : run scripts in CGI-mode:
- set environment variables with HTTP-request information
- write POST-data to script STDIN (if not set -form)
- write POST|PUT|PATCH-data to script STDIN (if not set -form)
- parse headers from script (eg: "Location: URL\n\n")
-export-vars=var: export environment vars ("VAR1,VAR2,...")
-export-all-vars: export all current environment vars
Expand Down
8 changes: 4 additions & 4 deletions shell2http.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ func execShellCommand(appConfig Config, shell string, params []string, req *http
if appConfig.setCGI {
setCGIEnv(osExecCommand, req, appConfig)

// get POST data to stdin of script (if not parse form vars above)
if req.Method == "POST" && !appConfig.setForm {
// get request body data data to stdin of script (if not parse form vars above)
if (req.Method == "POST" || req.Method == "PUT" || req.Method == "PATCH") && !appConfig.setForm {
if stdin, pipeErr := osExecCommand.StdinPipe(); pipeErr != nil {
log.Println("write POST data to shell failed:", pipeErr)
log.Println("write request body data to shell failed:", pipeErr)
} else {
waitPipeWrite = true
go func() {
Expand All @@ -394,7 +394,7 @@ func execShellCommand(appConfig Config, shell string, params []string, req *http

if waitPipeWrite {
if pipeErr := <-pipeErrCh; pipeErr != nil {
log.Println("write POST data to shell failed:", pipeErr)
log.Println("write request body data to shell failed:", pipeErr)
}
}

Expand Down

0 comments on commit 0a22a21

Please sign in to comment.