2

Does Google App Engine allow compression of the results? For example, I have the following curl request:

$ curl --location --request GET 'https://premiere-stage2.uk.r.appspot.com/' \
> --header 'Accept-Encoding: gzip, deflate, br'

And the response is not compressed. Compare this with something like:

$ curl --location -X GET 'https://google.com' --header 'Accept-Encoding: gzip, deflate, br'
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.

Or, is there something manual I need to set up? I would think the last resort would be to do the compression in the application endpoints themselves, or is that how it needs to be done?

David542
  • 104,438
  • 178
  • 489
  • 842
  • What is the HTTP response header **content-type** returned by your code? In order to compress, App Engine requires compatible content such as HTML, CSS, JavaScript, etc. (text-based data). The curl command can tell you what the response headers are (the -v option). – John Hanley Jul 24 '22 at 07:03
  • 1
    @JohnHanley oh thank you for pointing that out! Yes, once I make sure the content-header is set and the content itself is valid it compresses it correctly, in this case using gzip: `$ curl --location --request GET 'https://premiere-stage2.uk.r.appspot.com/html' --header 'Accept-Encoding: gzip, deflate, br' -v` – David542 Jul 24 '22 at 07:28
  • Post an answer with the change you made. This will help others. – John Hanley Jul 24 '22 at 07:29

2 Answers2

1

Expanding on John Hanley's suggestion in a comment, there are two parts to this.

  1. You have to set the Accept-Encoding header in the request.
  2. Second, the response itself should have the proper content- or mime-type, such as text/html or whatever it needs to be. Often the web server will ignore compression if the mime-type isn't in a certain list.
  3. Third, to ensure that the headers in both the requests and responses are correct you can use the -v flag in curl.
  4. Finally, it seems the content needs to be over a certain size for the web server to bother compressing it. So, for example, if the content-length is 3, it's not going to be compressed, though I'm not sure exactly what this is.

Putting it all together:

$ curl --location --request GET 'https://premiere-stage2.uk.r.appspot.com/html' 
        --header 'Accept-Encoding: gzip, deflate, br' 
        -v

References:

  • curl
  • GAE (a bit buried, under the Go documentation)
David542
  • 104,438
  • 178
  • 489
  • 842
0

According to documentation

For example, the server may automatically send a gzipped response depending on the value of the Accept-Encoding request header. The application itself does not need to know which content encodings the client can accept.

That gives the impression it should. But the same documentation also says

In addition, the following headers are removed from incoming requests because they relate to the transfer of the HTTP data between the client and server:

  • Accept-Encoding

I tested against our production site and in FireFox, Web Developer Tool shows Accept-Encoding: gzip, deflate, br as a request header and a response header of content-encoding: gzip

However, when I tested against local/dev of our site, Web Developer Tool shows Accept-Encoding: gzip, deflate, br as a request header but the response header didn't include content-encoding: gzip. In addition, printing the headers in Flask/Python, gave a value of None for Accept-Encoding

Deleplace
  • 6,812
  • 5
  • 28
  • 41
NoCommandLine
  • 5,044
  • 2
  • 4
  • 15
  • local/dev: is this with dev_appserver.py? If so, it is expected that transport encoding compression is not the same as the "production" servers – Deleplace Nov 29 '22 at 09:54