Add options for read timeout to tusd command

Fixes #24
This commit is contained in:
Marius 2015-10-16 20:02:08 +02:00
parent 7d25a9e65b
commit acd3a63213
1 changed files with 10 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"time"
) )
var httpHost string var httpHost string
@ -16,6 +17,7 @@ var maxSize int64
var dir string var dir string
var storeSize int64 var storeSize int64
var basepath string var basepath string
var timeout int64
var stdout = log.New(os.Stdout, "[tusd] ", 0) var stdout = log.New(os.Stdout, "[tusd] ", 0)
var stderr = log.New(os.Stderr, "[tusd] ", 0) var stderr = log.New(os.Stderr, "[tusd] ", 0)
@ -27,6 +29,7 @@ func init() {
flag.StringVar(&dir, "dir", "./data", "Directory to store uploads in") flag.StringVar(&dir, "dir", "./data", "Directory to store uploads in")
flag.Int64Var(&storeSize, "store-size", 0, "Size of disk space allowed to storage") flag.Int64Var(&storeSize, "store-size", 0, "Size of disk space allowed to storage")
flag.StringVar(&basepath, "base-path", "/files/", "Basepath of the hTTP server") flag.StringVar(&basepath, "base-path", "/files/", "Basepath of the hTTP server")
flag.Int64Var(&timeout, "timeout", 30*1000, "Read timeout for connections in milliseconds")
flag.Parse() flag.Parse()
} }
@ -78,8 +81,13 @@ func main() {
}() }()
http.Handle(basepath, http.StripPrefix(basepath, handler)) http.Handle(basepath, http.StripPrefix(basepath, handler))
err = http.ListenAndServe(address, nil)
if err != nil { server := &http.Server{
Addr: address,
ReadTimeout: time.Duration(timeout) * time.Millisecond,
}
if err = server.ListenAndServe(); err != nil {
stderr.Fatalf("Unable to listen: %s", err) stderr.Fatalf("Unable to listen: %s", err)
} }
} }