Issue with custom HTTP headers for tasks in Task Queue

46 views
Skip to first unread message

Ian

unread,
Dec 25, 2016, 4:58:58 PM12/25/16
to google-appengine-go
Hello everyone!

We try to set HTTP headers (for example the creation unixtime) for our tasks but neither do they show up in the Task Queue interface nor are they present when the task gets executed.

Here is our function that creates tasks and should add custom HTTP headers. Do we miss something? It should be possible

    // Additional HTTP headers to pass at the task's execution time.
    // To schedule the task to be run with an alternate app version
    // or backend, set the "Host" header.
    Header http.Header

// Create a task with a JSON object as payload when "method" is POST or PUT
func makeTask(name, method, path string, data interface{}) (*taskqueue.Task, error) {
    // check validity
    m := strings.ToUpper(method)
    if m != "POST" && m != "GET" && m != "PUT" {
        return nil, errors.New("HTTP Method " + m + " not supported")
    }

    h := make(http.Header)
    h.Set("Content-Type", "application/json")
    h.Set("x-custom-header-task-scheduled", string(time.Now().Unix()))

    t := taskqueue.Task{
        Name:   name,
        Path:   path,
        Header: h,
        Method: strings.ToUpper(method),
    }

    // add json payload
    if strings.ToLower(method) == "post" || strings.ToLower(method) == "put" {
        payload, err := json.Marshal(data)
        if err != nil {
            return nil, errors.New("Data is not well formatted JSON")
        }

        t.Payload = payload
    }

    return &t, nil
}

Thank you and Happy Holidays!
Ian
Reply all
Reply to author
Forward
0 new messages