aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/cgi/host.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-03-29 16:35:33 +1100
committerBrad Fitzpatrick <bradfitz@golang.org>2016-03-29 06:57:05 +0000
commit45d334ecf1b2bcbf0f8667d4c772ef3db0e03587 (patch)
tree7d33496e247905c1385bedc3415610575dc0d328 /src/net/http/cgi/host.go
parent093a9a1f5673d71377d4f0ef3f41a5618bf2512c (diff)
downloadgo-45d334ecf1b2bcbf0f8667d4c772ef3db0e03587.tar.xz
net/http/cgi: allow CGI host to configure where child's stderr goes
Patch originally from Steven Hartland. Tweaked a bit & added a test. Fixes #7197 Change-Id: I09012b4674e7c641dba31a24e9758cedb898d3ee Reviewed-on: https://go-review.googlesource.com/21196 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/cgi/host.go')
-rw-r--r--src/net/http/cgi/host.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/net/http/cgi/host.go b/src/net/http/cgi/host.go
index b2657b13a8..2eea64334b 100644
--- a/src/net/http/cgi/host.go
+++ b/src/net/http/cgi/host.go
@@ -58,6 +58,7 @@ type Handler struct {
InheritEnv []string // environment variables to inherit from host, as "key"
Logger *log.Logger // optional log for errors or nil to use log.Print
Args []string // optional arguments to pass to child process
+ Stderr io.Writer // optional stderr for the child process; nil means os.Stderr
// PathLocationHandler specifies the root http Handler that
// should handle internal redirects when the CGI process
@@ -70,6 +71,13 @@ type Handler struct {
PathLocationHandler http.Handler
}
+func (h *Handler) stderr() io.Writer {
+ if h.Stderr != nil {
+ return h.Stderr
+ }
+ return os.Stderr
+}
+
// removeLeadingDuplicates remove leading duplicate in environments.
// It's possible to override environment like following.
// cgi.Handler{
@@ -204,7 +212,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
Args: append([]string{h.Path}, h.Args...),
Dir: cwd,
Env: env,
- Stderr: os.Stderr, // for now
+ Stderr: h.stderr(),
}
if req.ContentLength != 0 {
cmd.Stdin = req.Body