Firebase Cloud Functions (HTTP Triggers + gzip)

2,257 views
Skip to first unread message

Ivan Rocha

unread,
Jun 27, 2017, 2:25:36 PM6/27/17
to Firebase Google Group
Hi,

   Does any one knows how to send gzipped content using Firebase Cloud Functions + HTTP Trigger? It seems that even if you set Content-Encoding header and send gzip data, everything is ignored... 

   Regards,

       Ivan


Chris Raynor

unread,
Jun 27, 2017, 2:46:55 PM6/27/17
to Firebase Google Group
Hi Ivan

Your function will have to handle the compression based on the input - Cloud Functions will not do anything here in this regards

The good news is this is pretty simple using the compression npm package:

exports.myFunc = functions.https.onRequest((req, res) => {
 
compression(req, res, () => { });
});




--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fcb2a735-89cd-40be-b6a5-8171465b97ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan Rocha

unread,
Jun 27, 2017, 8:23:47 PM6/27/17
to Firebase Google Group
Thanks Chris, but I found the 'real' problem that I was facing. You only need to use a combination of request headers (Accept-Encoding, User-Agent) supporting compressed output, see:

curl -v "https://us-central1-<project>.cloudfunctions.net/test" -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" -H "Accept-Encoding: gzip"

> GET /test HTTP/1.1
> Host: us-central1-<project>.cloudfunctions.net
> Accept: */*
> User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
> Accept-Encoding: gzip
< HTTP/1.1 200 OK
< content-type: application/json; charset=utf-8
...
< Content-Encoding: gzip
...
< Server: Google Frontend
< Transfer-Encoding: chunked
...

Caveat:
If you send an user agent like curl/7.47.0 or HTTPie/0.9.2, the output will not be compressed. (weird)

I tried using the compression module and I got the same behavior as above.

Regards,

    Ivan
Reply all
Reply to author
Forward
0 new messages