Golang ResponseWriter为大型有效载荷给出错误

时间:2019-05-09 13:06:41

标签: http go google-cloud-platform google-cloud-functions slice

我有以下Go代码:

func EntryFn(w http.ResponseWriter, r *http.Request) {
    req := Request{}

    b, err := ioutil.ReadAll(r.Body)
    if err != nil {
        http.Error(w, "Could not read request", http.StatusBadRequest)
    }
    if err := xml.Unmarshal(b, &req); err != nil {
        http.Error(w, "Could not parse request", http.StatusBadRequest)
    }

    g := GetGoogleBucket()

    dataReqList := req.DataReqObject.DataRequestList

    res := Response{}

    for _, element := range dataReqList {

        ... my logic ...

        var appendedBytes []byte
        for {
            decryptedFileBuffer, err := opusFh.GetNextDecryptedPage()
            if err != nil {
                break
            }
            appendedBytes = append(appendedBytes, decryptedFileBuffer...)
        }

        res.DataResponseObject.AddFileContents(recordingID, appendedBytes)  
    }   

    xmlstring, err := xml.MarshalIndent(res, "", "    ");

    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }       

    xmlstring = []byte(xml.Header + string(xmlstring))

    fmt.Println(xmlstring)

    w.Header().Set("Content-Type", "application/xml")
    w.Write(xmlstring)

    fmt.Println("Batch Complete")
}

代码已部署在Google Cloud Function中。

当xmlstring的总大小小于10 MB时,我得到正确的响应。但是当大小增加到更多时,出现以下错误:

  

错误:函数响应不正确。函数调用原为   中断。

     

错误:无法处理请求

ResponseWriter是否有任何限制?我该怎么解决?

0 个答案:

没有答案