AppEngine gzip compressing

2019-03-20 12:14发布

I'm trying to gzip responses from GAE server, but receive null in Content-Encoding.

I have the following code:

connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", 
          "application/json; charset=utf-8"); //"application/json; charset=utf-8"
connection.setRequestProperty("Accept-Encoding", "gzip");
connection.setRequestProperty("User-Agent", "gzip");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);

//write
//read

System.out.println("Content-Encoding " + connection.getContentEncoding());

I've read that on GAE servers do compressing automatically. So what can be the problem?

1条回答
戒情不戒烟
2楼-- · 2019-03-20 12:40

The App Engine frontend servers rely on a number of factors, including the Accept-Encoding and User-Agent headers to determine if they should compress responses. They do this because there are a number of user agents out there that claim to accept gzipped responses, but actually can't understand them.

Try setting your user agent to something sensible (and not 'gzip', which isn't a real user agent), and see if that makes any difference.

查看更多
登录 后发表回答