summaryrefslogtreecommitdiffhomepage
path: root/caddyhttp/fastcgi/fastcgi.go
diff options
context:
space:
mode:
authorericdreeves <[email protected]>2016-11-29 20:26:51 -0600
committerericdreeves <[email protected]>2016-12-03 16:15:41 -0600
commit5874fbeb7e5f3420763d4bdefe5c72d102f05e04 (patch)
tree997c371648d5f474ce965bf0c429b8fc48ff2bbf /caddyhttp/fastcgi/fastcgi.go
parent17e7e6076a5567e6c8ee61ac04316e3399be3155 (diff)
downloadcaddy-5874fbeb7e5f3420763d4bdefe5c72d102f05e04.tar.gz
caddy-5874fbeb7e5f3420763d4bdefe5c72d102f05e04.zip
Add send_timeout property to fastcgi directive.
* Convert rwc field on FCGIClient from type io.ReadWriteCloser to net.Conn. * Return HTTP 504 to the client when a timeout occurs. * In Handler.ServeHTTP(), close the connection before returning an HTTP 502/504. * Refactor tests and add coverage.
Diffstat (limited to 'caddyhttp/fastcgi/fastcgi.go')
-rw-r--r--caddyhttp/fastcgi/fastcgi.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/caddyhttp/fastcgi/fastcgi.go b/caddyhttp/fastcgi/fastcgi.go
index 74999592f..ac29eb739 100644
--- a/caddyhttp/fastcgi/fastcgi.go
+++ b/caddyhttp/fastcgi/fastcgi.go
@@ -6,6 +6,7 @@ package fastcgi
import (
"errors"
"io"
+ "net"
"net/http"
"os"
"path"
@@ -82,7 +83,9 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
if err != nil {
return http.StatusBadGateway, err
}
+ defer fcgiBackend.Close()
fcgiBackend.SetReadTimeout(rule.ReadTimeout)
+ fcgiBackend.SetSendTimeout(rule.SendTimeout)
var resp *http.Response
contentLength, _ := strconv.Atoi(r.Header.Get("Content-Length"))
@@ -97,8 +100,12 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
resp, err = fcgiBackend.Post(env, r.Method, r.Header.Get("Content-Type"), r.Body, contentLength)
}
- if err != nil && err != io.EOF {
- return http.StatusBadGateway, err
+ if err != nil {
+ if err, ok := err.(net.Error); ok && err.Timeout() {
+ return http.StatusGatewayTimeout, err
+ } else if err != io.EOF {
+ return http.StatusBadGateway, err
+ }
}
// Write response header
@@ -110,8 +117,6 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
return http.StatusBadGateway, err
}
- defer rule.dialer.Close(fcgiBackend)
-
// Log any stderr output from upstream
if stderr := fcgiBackend.StdErr(); stderr.Len() != 0 {
// Remove trailing newline, error logger already does this.
@@ -306,6 +311,9 @@ type Rule struct {
// The duration used to set a deadline when reading from the FastCGI server.
ReadTimeout time.Duration
+ // The duration used to set a deadline when sending to the FastCGI server.
+ SendTimeout time.Duration
+
// FCGI dialer
dialer dialer
}