All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mnubo.java.sdk.client.mapper.GzipRequestInterceptor Maven / Gradle / Ivy

There is a newer version: 1.14.4
Show newest version
package com.mnubo.java.sdk.client.mapper;


import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

public class GzipRequestInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHttpRequestExecution execution) throws IOException {
        request.getHeaders().add("Content-Encoding", "gzip");

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try (GZIPOutputStream gzip = new GZIPOutputStream(stream)) {
            gzip.write(bytes);
        }
        return execution.execute(request, stream.toByteArray());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy