Skip to content

Commit

Permalink
Merge pull request ethereum#412 from cooganb/200-json-reply-1
Browse files Browse the repository at this point in the history
swarm: creates a 200 server response when localhost is pinged by JSON
  • Loading branch information
nonsense authored Apr 27, 2018
2 parents 9cbaf29 + 2671711 commit b3b6fbb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions swarm/api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,13 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
return
}

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, "/"))
if err != nil {
Respond(w, req, fmt.Sprintf("invalid URI %q", r.URL.Path), http.StatusBadRequest)
Expand Down

0 comments on commit b3b6fbb

Please sign in to comment.