appengine/go11x/tasks: use r.Header.Get
@@ -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)
