serve http: make it compile on go1.6 and go1.7

This commit is contained in:
Nick Craig-Wood 2017-10-26 21:52:29 +01:00
parent 39b9f80302
commit 96665c16cb
3 changed files with 33 additions and 6 deletions

View file

@ -9,7 +9,6 @@ import (
"path" "path"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/ncw/rclone/cmd" "github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs" "github.com/ncw/rclone/fs"
@ -77,12 +76,11 @@ func (s *server) serve() {
mux.HandleFunc("/", s.handler) mux.HandleFunc("/", s.handler)
// FIXME make a transport? // FIXME make a transport?
httpServer := &http.Server{ httpServer := &http.Server{
Addr: s.bindAddress, Addr: s.bindAddress,
Handler: mux, Handler: mux,
ReadHeaderTimeout: 10 * time.Second, // time to send the headers MaxHeaderBytes: 1 << 20,
IdleTimeout: 60 * time.Second, // time to keep idle connections open
MaxHeaderBytes: 1 << 20,
} }
initServer(httpServer)
fs.Logf(s.f, "Serving on http://%s/", bindAddress) fs.Logf(s.f, "Serving on http://%s/", bindAddress)
log.Fatal(httpServer.ListenAndServe()) log.Fatal(httpServer.ListenAndServe())
} }

View file

@ -0,0 +1,16 @@
// HTTP parts go1.8+
//+build go1.8
package http
import (
"net/http"
"time"
)
// Initialise the http.Server for pre go1.8
func initServer(s *http.Server) {
s.ReadHeaderTimeout = 10 * time.Second // time to send the headers
s.IdleTimeout = 60 * time.Second // time to keep idle connections open
}

View file

@ -0,0 +1,13 @@
// HTTP parts pre go1.8
//+build !go1.8
package http
import (
"net/http"
)
// Initialise the http.Server for pre go1.8
func initServer(s *http.Server) {
}