Skip to content

Commit

Permalink
Updating code so that caduceus only supports POST method requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holaday, Sean authored and Holaday, Sean committed Apr 12, 2017
1 parent 78175ce commit 8c22cf4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/caduceus/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"github.com/Comcast/webpa-common/logging"
"io/ioutil"
"net/http"
Expand All @@ -21,17 +22,22 @@ type ServerHandler struct {
func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
defer request.Body.Close()

sh.Info("Receiving incoming post...")
sh.Info("Receiving incoming request...")

timeStamps := CaduceusTimestamps{
TimeReceived: time.Now(),
}

if request.Method != "POST" {
response.WriteHeader(http.StatusBadRequest)
response.Write([]byte(fmt.Sprintf("Unsupported method \"%s\"... Caduceus only supports \"POST\" method.\n", request.Method)))
return
}

myPayload, err := ioutil.ReadAll(request.Body)
if err != nil {
statusMsg := "Unable to retrieve the request body: " + err.Error() + ".\n"
response.WriteHeader(http.StatusBadRequest)
response.Write([]byte(statusMsg))
response.Write([]byte(fmt.Sprintf("Unable to retrieve the request body: %s.\n", err.Error)))
return
}

Expand Down

0 comments on commit 8c22cf4

Please sign in to comment.