From 2671711aff05d39c2339b9a5dd31b68b07813a60 Mon Sep 17 00:00:00 2001 From: cooganb Date: Thu, 19 Apr 2018 12:59:44 -0500 Subject: [PATCH] swarm: creates a 200 server response when localhost is pinged by JSON --- swarm/api/http/server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index 65f6afab72..dfa9ecfe63 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -578,6 +578,13 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.logDebug("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, r.URL.Host, r.URL.Path, r.Referer(), r.Header.Get("Accept")) + if r.RequestURI == "/" && strings.Contains(r.Header.Get("Accept"), "application/json") { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode("Welcome to Swarm!") + return + } + uri, err := api.Parse(strings.TrimLeft(r.URL.Path, "/")) req := &Request{Request: *r, uri: uri} if err != nil {