Commit d47b0419 authored by Alexander Danilov's avatar Alexander Danilov Committed by Matt Holt

fastcgi: Add default timeouts (#2265)

Default fastcgi timeout is 60 seconds
Add tests
parent dfbc2e81
...@@ -27,6 +27,8 @@ import ( ...@@ -27,6 +27,8 @@ import (
"github.com/mholt/caddy/caddyhttp/httpserver" "github.com/mholt/caddy/caddyhttp/httpserver"
) )
var defaultTimeout = 60 * time.Second
func init() { func init() {
caddy.RegisterPlugin("fastcgi", caddy.Plugin{ caddy.RegisterPlugin("fastcgi", caddy.Plugin{
ServerType: "http", ServerType: "http",
...@@ -78,6 +80,9 @@ func fastcgiParse(c *caddy.Controller) ([]Rule, error) { ...@@ -78,6 +80,9 @@ func fastcgiParse(c *caddy.Controller) ([]Rule, error) {
rule := Rule{ rule := Rule{
Root: absRoot, Root: absRoot,
Path: args[0], Path: args[0],
ConnectTimeout: defaultTimeout,
ReadTimeout: defaultTimeout,
SendTimeout: defaultTimeout,
} }
upstreams := []string{args[1]} upstreams := []string{args[1]}
......
...@@ -19,6 +19,7 @@ import ( ...@@ -19,6 +19,7 @@ import (
"fmt" "fmt"
"net" "net"
"testing" "testing"
"time"
"github.com/mholt/caddy" "github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver" "github.com/mholt/caddy/caddyhttp/httpserver"
...@@ -53,6 +54,18 @@ func TestSetup(t *testing.T) { ...@@ -53,6 +54,18 @@ func TestSetup(t *testing.T) {
if addr != "127.0.0.1:9000" { if addr != "127.0.0.1:9000" {
t.Errorf("Expected 127.0.0.1:9000 as the Address") t.Errorf("Expected 127.0.0.1:9000 as the Address")
} }
if myHandler.Rules[0].ConnectTimeout != 60*time.Second {
t.Errorf("Expected default value of 60 seconds")
}
if myHandler.Rules[0].ReadTimeout != 60*time.Second {
t.Errorf("Expected default value of 60 seconds")
}
if myHandler.Rules[0].SendTimeout != 60*time.Second {
t.Errorf("Expected default value of 60 seconds")
}
} }
func TestFastcgiParse(t *testing.T) { func TestFastcgiParse(t *testing.T) {
...@@ -69,6 +82,7 @@ func TestFastcgiParse(t *testing.T) { ...@@ -69,6 +82,7 @@ func TestFastcgiParse(t *testing.T) {
Ext: ".php", Ext: ".php",
SplitPath: ".php", SplitPath: ".php",
IndexFiles: []string{"index.php"}, IndexFiles: []string{"index.php"},
SendTimeout: 60 * time.Second,
}}}, }}},
{`fastcgi / 127.0.0.1:9001 { {`fastcgi / 127.0.0.1:9001 {
split .html split .html
...@@ -79,6 +93,7 @@ func TestFastcgiParse(t *testing.T) { ...@@ -79,6 +93,7 @@ func TestFastcgiParse(t *testing.T) {
Ext: "", Ext: "",
SplitPath: ".html", SplitPath: ".html",
IndexFiles: []string{}, IndexFiles: []string{},
SendTimeout: 60 * time.Second,
}}}, }}},
{`fastcgi / 127.0.0.1:9001 { {`fastcgi / 127.0.0.1:9001 {
split .html split .html
...@@ -91,6 +106,17 @@ func TestFastcgiParse(t *testing.T) { ...@@ -91,6 +106,17 @@ func TestFastcgiParse(t *testing.T) {
SplitPath: ".html", SplitPath: ".html",
IndexFiles: []string{}, IndexFiles: []string{},
IgnoredSubPaths: []string{"/admin", "/user"}, IgnoredSubPaths: []string{"/admin", "/user"},
SendTimeout: 60 * time.Second,
}}},
{`fastcgi / 127.0.0.1:9001 {
send_timeout 30s
}`,
false, []Rule{{
Path: "/",
balancer: &roundRobin{addresses: []string{"127.0.0.1:9001"}},
Ext: "",
IndexFiles: []string{},
SendTimeout: 30 * time.Second,
}}}, }}},
} }
for i, test := range tests { for i, test := range tests {
...@@ -146,6 +172,11 @@ func TestFastcgiParse(t *testing.T) { ...@@ -146,6 +172,11 @@ func TestFastcgiParse(t *testing.T) {
t.Errorf("Test %d expected %dth FastCGI IgnoredSubPaths to be %s , but got %s", t.Errorf("Test %d expected %dth FastCGI IgnoredSubPaths to be %s , but got %s",
i, j, test.expectedFastcgiConfig[j].IgnoredSubPaths, actualFastcgiConfig.IgnoredSubPaths) i, j, test.expectedFastcgiConfig[j].IgnoredSubPaths, actualFastcgiConfig.IgnoredSubPaths)
} }
if actualFastcgiConfig.SendTimeout != test.expectedFastcgiConfig[j].SendTimeout {
t.Errorf("Test %d expected %dth FastCGI SendTimeout to be %s , but got %s",
i, j, test.expectedFastcgiConfig[j].SendTimeout, actualFastcgiConfig.SendTimeout)
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment