File tree Expand file tree Collapse file tree
core/src/main/java/xyz/gianlu/librespot/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import com .spotify .explicit .ExplicitContentPubsub .UserAttributesUpdate ;
1111import okhttp3 .Authenticator ;
1212import okhttp3 .*;
13+ import okio .BufferedSink ;
14+ import okio .GzipSink ;
15+ import okio .Okio ;
1316import org .apache .log4j .Logger ;
1417import org .jetbrains .annotations .Contract ;
1518import org .jetbrains .annotations .NotNull ;
@@ -142,6 +145,36 @@ public Request authenticate(Route route, @NotNull Response response) {
142145 }
143146 }
144147
148+ builder .addInterceptor (chain -> {
149+ Request original = chain .request ();
150+ RequestBody body ;
151+ if ((body = original .body ()) == null || original .header ("Content-Encoding" ) != null )
152+ return chain .proceed (original );
153+
154+ Request compressedRequest = original .newBuilder ()
155+ .header ("Content-Encoding" , "gzip" )
156+ .method (original .method (), new RequestBody () {
157+ @ Override
158+ public MediaType contentType () {
159+ return body .contentType ();
160+ }
161+
162+ @ Override
163+ public long contentLength () {
164+ return -1 ;
165+ }
166+
167+ @ Override
168+ public void writeTo (@ NotNull BufferedSink sink ) throws IOException {
169+ try (BufferedSink gzipSink = Okio .buffer (new GzipSink (sink ))) {
170+ body .writeTo (gzipSink );
171+ }
172+ }
173+ }).build ();
174+
175+ return chain .proceed (compressedRequest );
176+ });
177+
145178 return builder .build ();
146179 }
147180
You can’t perform that action at this time.
0 commit comments