Google App Engine - how to properly execute gzip requests

In my Google App Engine application (a standard environment written in Java + Scala), I want some of my server requests to be gzip. After several experiments, I got the job mostly, but there are a few points that I'm not sure about. I did not find much documentation about the correct use of gzip on the client side, most of the documentation and examples seemed to bother the server encoding its responses, so I'm not sure that I am doing everything as I should.

I send the request this way (using akka.http in the client application):

        val uploadReq = Http().singleRequest(
          HttpRequest(
            uri = "https://xxx.appspot.com/upload-a-file",
            method = HttpMethods.POST,
            headers = List(headers.`Content-Encoding`(HttpEncodings.gzip)) 
            entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`,  Gzip.encode(ByteString(bytes)))
          )
        )

On the production GAE server, I get the already processed gzipped request object, and the encoding header is still present. This is different on the development server, the header is also present, but the request body is still gzipped.

The code to decode the request input stream is not a problem, but I have not found a clean way to check my server code if I have to decode the request body or not. My current solution is that if the client knows that it is communicating with the development server, it does not use gzip encoding at all, and I never try to decode the request body, since I rely on the Google App Engine to do this for me .

  • Do I have to encode the request body differently on the client?
  • Is there any other way of recognition on the server if the requested request authority needs decoding or not?
  • , Google App Engine ?
+4
1

: , , , , gzipped, , . prod ( App Engine , ) dev ( ). Scala :

def decompressStream(input: InputStream): InputStream = {
  val pushbackInputStream = new PushbackInputStream(input, 2)
  val signature = new Array[Byte](2)
  pushbackInputStream.read(signature)
  pushbackInputStream.unread(signature)
  if (signature(0) == 0x1f.toByte && signature(1) == 0x8b.toByte) {
    new GZIPInputStream(pushbackInputStream)
  } else pushbackInputStream
}

, - , 0x1f/0x8b , . , .

0

Source: https://habr.com/ru/post/1683502/


All Articles