mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
FastCGI: separate standard and error output responses.
This commit is contained in:
parent
aba0ae358e
commit
b7fd1f4e9e
2 changed files with 31 additions and 5 deletions
|
@ -115,7 +115,12 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||
return http.StatusBadGateway, err
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
// FastCGI stderr outputs
|
||||
if fcgi.stderr.Len() != 0 {
|
||||
err = LogError(fcgi.stderr.String())
|
||||
}
|
||||
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,3 +286,11 @@ var (
|
|||
// ErrIndexMissingSplit describes an index configuration error.
|
||||
ErrIndexMissingSplit = errors.New("configured index file(s) must include split value")
|
||||
)
|
||||
|
||||
// LogError is a non fatal error that allows requests to go through.
|
||||
type LogError string
|
||||
|
||||
// Error satisfies error interface.
|
||||
func (l LogError) Error() string {
|
||||
return string(l)
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ type FCGIClient struct {
|
|||
rwc io.ReadWriteCloser
|
||||
h header
|
||||
buf bytes.Buffer
|
||||
stderr bytes.Buffer
|
||||
keepAlive bool
|
||||
reqID uint16
|
||||
}
|
||||
|
@ -346,10 +347,22 @@ func (w *streamReader) Read(p []byte) (n int, err error) {
|
|||
|
||||
if len(p) > 0 {
|
||||
if len(w.buf) == 0 {
|
||||
rec := &record{}
|
||||
w.buf, err = rec.read(w.c.rwc)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
// filter outputs for error log
|
||||
for {
|
||||
rec := &record{}
|
||||
var buf []byte
|
||||
buf, err = rec.read(w.c.rwc)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// standard error output
|
||||
if rec.h.Type == Stderr {
|
||||
w.c.stderr.Write(buf)
|
||||
continue
|
||||
}
|
||||
w.buf = buf
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue