diff --git a/testing/servers/http/http.go b/testing/servers/http/http.go index 47ecca114..230e973ce 100644 --- a/testing/servers/http/http.go +++ b/testing/servers/http/http.go @@ -10,9 +10,10 @@ type Server struct { Port net.Port PathHandler map[string]http.HandlerFunc accepting bool + server *http.Server } -func (server *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) { +func (s *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) { if req.URL.Path == "/" { resp.Header().Set("Content-Type", "text/plain; charset=utf-8") resp.WriteHeader(http.StatusOK) @@ -20,17 +21,21 @@ func (server *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) { return } - handler, found := server.PathHandler[req.URL.Path] + handler, found := s.PathHandler[req.URL.Path] if found { handler(resp, req) } } -func (server *Server) Start() (net.Destination, error) { - go http.ListenAndServe("127.0.0.1:"+server.Port.String(), server) - return net.TCPDestination(net.LocalHostIP, net.Port(server.Port)), nil +func (s *Server) Start() (net.Destination, error) { + s.server = &http.Server{ + Addr: "127.0.0.1:" + s.Port.String(), + Handler: s, + } + go s.server.ListenAndServe() + return net.TCPDestination(net.LocalHostIP, net.Port(s.Port)), nil } -func (v *Server) Close() { - v.accepting = false +func (s *Server) Close() { + s.server.Close() }