Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Gossiper_server update
Reply with 404 error when unintended directories are accessed.
  • Loading branch information
mwl11002 committed Apr 28, 2022
1 parent 2f70ec5 commit 4cba860
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions CTng/server/Gossiper_server.go
Expand Up @@ -29,7 +29,9 @@ import (
)

type Gossiper interface {
// Response to entering the 'base page' of a gossiper.
// Error response to "/".
basePage()
// Error response to "/gossiper/". Can replace with informative home page in the future.
homePage()
// HTTP POST request, receive a JSON object from another gossiper or connected monitor.
// /gossip/push-data
Expand Down Expand Up @@ -68,7 +70,10 @@ func initializeGossiperEndpoints(c *gossip.GossiperContext) {
// MUX which routes HTTP directories to functions.
gorillaRouter := mux.NewRouter().StrictSlash(true)

// homePage() is ran when base directory is accessed, this allows for confirmation that a gossiper is working as expected.
// basePage returns a 404 error as it is currently not intended to be directly accessed.
gorillaRouter.HandleFunc("/", basePage)
// homePage() is ran "/gossip/" is accessed, separated to allow development of an informative homepage in the future.
// Returns a 404 error as it is currently not intended to be directly accessed.
gorillaRouter.HandleFunc("/gossip/", homePage)

// Inter-gossiper endpoints: Post/Get required
Expand All @@ -90,6 +95,12 @@ func initializeGossiperEndpoints(c *gossip.GossiperContext) {
os.Exit(1)
}

// Reply with a 404 error when "/" is accessed.
func basePage(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Page not found.", http.StatusNotFound)
}

// Reply with a 404 error when "/gossip/" is accessed.
func homePage(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Page not found.", http.StatusNotFound)
}
Expand Down

0 comments on commit 4cba860

Please sign in to comment.