Google App Engine上的HTTP响应标题有大小限制吗? [英] Is there a size limit for HTTP response headers on Google App Engine?

查看:108
本文介绍了Google App Engine上的HTTP响应标题有大小限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在appspot上运行一些处理程序代码的分析器,并且正在寻找一种方法来显示pstats输出,而不直接写入响应主体(这对处理程序响应结构化数据(例如JSON)是有问题的)。

我决定尝试将输出写入响应头文件,并将一些js添加到可以解析头文件和控制台的html渲染处理程序中.log()它(原来是非常简单和方便的工作)。对于非HTML渲染处理程序,我想我可能会尝试构建一个chrome扩展来执行类似的操作,但当然,每当我对这样的处理程序进行ajax调用时,调用页面(使用js解析

当我在 dev_appserver 上进行测试时,所有这些看起来都不错,但后来我部署到appspot,发现我的自定义标题从未出现。我在这个项目中有类似的代码片段,用于跟踪某些操作的执行时间,以及我编写的自定义头文件以显示正常。



我是假设appspot python运行时进程有一个限制,如果它大于特定长度,则忽略头,但是我没有看到开发人员站点上发布的任何大小。



如果实际上有一个限制,是否有人知道它是什么?

解决方案

我找不到任何关于此的文档,但整个标题行(包括键,冒号,冒号后的空格,但不包括 '\r\\\
')。



这是一个Go测试句柄:

  func测试(c appengine.Context,w http.ResponseWriter,r * http.Request){
l,err:= strconv.ParseInt (r.URL.Query()。戈t(len),10,64)
if err!= nil {
http.Error(w,,http.StatusBadRequest)
return
}
value:=
for l!= 0 {
value + =X
l--
}
w.Header()。Set (Set-Cookie值)
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)
}
$ b

len 查询参数设置为469是最大的值,它不会删除 Very-Very-Long-Test-Header 标题。 484是保留 Test-Header 标题的最大者,485是保留 Xxxxx ...的最大者头部。



它们全部合计为每行497,或者如果您愿意,495不包括


$ b

注意此限制不适用于传入(请求)标头。

< Set-Cookie 标题具有不同的限制:4108个字节,而不是497个。


I was trying to run a profiler on some handler code up on appspot and was looking for a way to show the pstats output without writing directly to the response body (which is problematic for handlers responding with structured data such as JSON).

I decided to try writing the output to the response header, and added some js to my html-rendering handlers that could parse the header and console.log() it (turned out to be pretty simple and convenient to work with). For the non-html rendering handlers, I was thinking I might try and build a chrome extension to do something similar, but of course, whenever I'm making an ajax call to such a handler, the calling page (with the js to parse the header) can step in and handle the display.

All this looked good as I was testing on dev_appserver, but then I deployed to appspot and found that my custom header never showed up. I have similar pieces of code in this project that track the elapsed execution time of certain operations, and the custom headers I write that stuff to shows up fine.

I'm assuming there's a limit in place on appspot python runtime process that omits the header if it's greater than a certain length, but I don't see the size published anywhere on the developer site.

If there is in fact a limit, does anyone know what it is?

解决方案

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.

这篇关于Google App Engine上的HTTP响应标题有大小限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆