Is there a size limit for HTTP response headers on Google App Engine?

心不动则不痛 提交于 2019-12-05 05:21:46

I cannot find any documentation about this, but the limit seems to be 497 bytes for the entire header line (including the key, the colon, the whitespace after the colon, but excluding the '\r\n' at the end of the line).

Here's a Go test handler:

func Test(c appengine.Context, w http.ResponseWriter, r *http.Request) {
    l, err := strconv.ParseInt(r.URL.Query().Get("len"), 10, 64)
    if err != nil {
        http.Error(w, "", http.StatusBadRequest)
        return
    }
    value := ""
    for l != 0 {
        value += "X"
        l--
    }
    w.Header().Set("Set-Cookie", value)
    w.Header().Set("Test-Header", value)
    w.Header().Set("Very-Very-Long-Test-Header", value)
    w.Header().Set(value, "Test-Value")
    w.WriteHeader(http.StatusNoContent)
}

Setting the len query parameter to 469 is the largest value that does not remove the Very-Very-Long-Test-Header header. 484 is the largest that will keep the Test-Header header, and 485 is the largest that will keep the Xxxxx… header.

They all add up to 497 per line, or if you will, 495 excluding the ": ".

NOTE that this limit does not apply to incoming (request) headers.

UPDATE: The Set-Cookie header has a different limit: 4108 bytes instead of 497.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!