开发者

How to detect HTTP response size in Google App Engine

开发者 https://www.devze.com 2023-03-18 22:56 出处:网络
I\'m writing an app for Google App Engine with Java. A certain servlet produces responses that may go over the 32 megabyte limit. On the development server, this does not seem to cause any issues. On

I'm writing an app for Google App Engine with Java. A certain servlet produces responses that may go over the 32 megabyte limit. On the development server, this does not seem to cause any issues. On the production server, I'll need a way to split the response over several requests.

I want to know what happens on the production server when the limit is exceeded. Does the PrintWriter throw an IOException when the limit is exceeded? Or is an exception only thrown when the servlet terminates? Ideally, I would like to be able to calculate th开发者_如何转开发e total response size before appending each section (without counting the bytes myself, because I don't know the size of the HTTP headers), so that I can properly clean up the end of the response (i.e. append "}" to complete the JSON object). Or is there a better way to handle this type of situation?


nick's right, the current response size limit is 32MB.

app engine buffers response data, so it doesn't see your response until your code has finished running, so it can't raise an exception or otherwise signal an error that your code can catch. instead, it returns a 500 to the client with a body like this:

HTTP response was too large: 34000134. The limit is: 33554432.

you can try it yourself by running this in http://shell.appspot.com/ :

print 'x' * 34 * 1000 * 1000

0

精彩评论

暂无评论...
验证码 换一张
取 消