Skip to content

Commit

Permalink
appengine/go11x/tasks: use r.Header.Get (GoogleCloudPlatform#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbpg committed Jun 1, 2020
1 parent 0204afd commit ebdf841
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions appengine/go11x/tasks/handle_task/handle_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,17 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {

// taskHandler processes task requests.
func taskHandler(w http.ResponseWriter, r *http.Request) {
t, ok := r.Header["X-Appengine-Taskname"]
if !ok || len(t[0]) == 0 {
taskName := r.Header.Get("X-Appengine-Taskname")
if taskName == "" {
// You may use the presence of the X-Appengine-Taskname header to validate
// the request comes from Cloud Tasks.
log.Println("Invalid Task: No X-Appengine-Taskname request header found")
http.Error(w, "Bad Request - Invalid Task", http.StatusBadRequest)
return
}
taskName := t[0]

// Pull useful headers from Task request.
q, ok := r.Header["X-Appengine-Queuename"]
queueName := ""
if ok {
queueName = q[0]
}
queueName := r.Header.Get("X-Appengine-Queuename")

// Extract the request body for further task details.
body, err := ioutil.ReadAll(r.Body)
Expand Down

0 comments on commit ebdf841

Please sign in to comment.