swagger-api / swagger-api/swagger-codegen

[All languages] Support for gzip compression

Open
#3,365 3 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature General: Suggestion
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

This is a feature request for two options enabling support for gzip compression for the generated API clients for all languages.

The first option would enable support for compression in API requests. When this option is turned on, the client would:

  1. Add Content-Encoding: gzip to the HTTP request headers
  2. Compress the HTTP request bodies using gzip

The second option would enable support for compression in API responses. When this option is turned on, the client would:

  1. Add Accept-Encoding: gzip to the HTTP request headers
  2. Decompress the bodies of HTTP responses with a response header of Content-Encoding: gzip

Ideally, both options would be on by default.

Related issues

#3279 discusses how to add gzip support to the Java API.

Suggest a Fix

For some languages, this won't be possible. For example, the JavaScript API presumably uses XmlHttpRequest behind the scenes when running in the browser, and the spec won't let you set encoding-related headers.

For other languages, though, this should be fairly straightforward. For example, in Java, adding support for GZIP compression for API requests and responses in the Jersey 1.x client consists of simply adding:

client.addFilter(new GZIPContentEncodingFilter());

to the rebuildHttpClient function in ApiClient.java. Passing in the parameter false to the constructor would enable it only for responses. Simply encapsulate this behaviour behind a couple of properties and you're done!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with related issue #3279 and the Java ApiClient.java example, especially the rebuildHttpClient entry point and GZIPContentEncodingFilter reference. Compare how request and response compression options could apply across generated client languages; done means the supported clients expose the requested behavior while documenting language limitations such as browser JavaScript.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript
Domain
api, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.