openapistack / openapi-backend

Build, Validate, Route, Authenticate and Mock using OpenAPI
https://openapistack.co
MIT License
609 stars 83 forks source link

GZIP compression for API responses? #588

Closed robogeek closed 1 year ago

robogeek commented 1 year ago

Is it possible for an API implemented with OpenAPI Backend to compress responses using GZIP?

I have such an API, and ran this test (going by advice found here https://davidwalsh.name/check-gzip):

$ curl -H "Accept-Encoding: gzip" -v -f http://localhost:9000/api/openadr/0.1/vens
*   Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> GET /api/openadr/0.1/vens HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/8.1.2
> Accept: */*
> Accept-Encoding: gzip
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 1234
< ETag: W/"4d2-7rJdn+XVdF223rzgKmYSISBaAtc"
< Date: Tue, 20 Jun 2023 20:06:52 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5

Notice that Accept-Encoding is set, but the response was not encoded.

anttiviljami commented 1 year ago

I feel that compression is clearly out of scope for OpenAPI backend. It’s pretty standard for most server implementations to support response compression with Accept Encoding headers out of the box. OpenAPI backend is designed to plug into a server / framework, not be the server.