Skip to content

Doc: gzip support in RestTemplate [SPR-7874] #12531

@spring-projects-issues

Description

@spring-projects-issues

Stephan Oudmaijer opened SPR-7874 and commented

The org.springframework.web.client.RestTemplate does not support gzip encoding. Please add an option to add headers to the request or provide built-in support for gzip encoding.

Now I have added a hack in my own GzipRestTemplate version:

public class GzipRestTemplate extends RestTemplate {

   @Override
    protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException {
        Assert.notNull(url, "'url' must not be null");
        Assert.notNull(method, "'method' must not be null");
        ClientHttpResponse response = null;
        try {
            ClientHttpRequest request = createRequest(url, method);
            if( request.getHeaders() != null ) {
                request.getHeaders().add("Accept-Encoding", "gzip,deflate"); // <- hack
            }

Affects: 3.0.5

Referenced from: commits 3d645cf

8 votes, 13 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions