{"action":"created","issue":{"url":"https://api.github.com/repos/square/okhttp/issues/350","labels_url":"https://api.github.com/repos/square/okhttp/issues/350/labels{/name}","comments_url":"https://api.github.com/repos/square/okhttp/issues/350/comments","events_url":"https://api.github.com/repos/square/okhttp/issues/350/events","html_url":"https://github.com/square/okhttp/issues/350","id":22554174,"number":350,"title":"Add GZip Request Compression","user":{"login":"johnlcox","id":474333,"avatar_url":"https://avatars.githubusercontent.com/u/474333?v=3","gravatar_id":"","url":"https://api.github.com/users/johnlcox","html_url":"https://github.com/johnlcox","followers_url":"https://api.github.com/users/johnlcox/followers","following_url":"https://api.github.com/users/johnlcox/following{/other_user}","gists_url":"https://api.github.com/users/johnlcox/gists{/gist_id}","starred_url":"https://api.github.com/users/johnlcox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnlcox/subscriptions","organizations_url":"https://api.github.com/users/johnlcox/orgs","repos_url":"https://api.github.com/users/johnlcox/repos","events_url":"https://api.github.com/users/johnlcox/events{/privacy}","received_events_url":"https://api.github.com/users/johnlcox/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/square/okhttp/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/square/okhttp/milestones/6","html_url":"https://github.com/square/okhttp/milestones/Icebox","labels_url":"https://api.github.com/repos/square/okhttp/milestones/6/labels","id":606107,"number":6,"title":"Icebox","description":null,"creator":{"login":"swankjesse","id":133019,"avatar_url":"https://avatars.githubusercontent.com/u/133019?v=3","gravatar_id":"","url":"https://api.github.com/users/swankjesse","html_url":"https://github.com/swankjesse","followers_url":"https://api.github.com/users/swankjesse/followers","following_url":"https://api.github.com/users/swankjesse/following{/other_user}","gists_url":"https://api.github.com/users/swankjesse/gists{/gist_id}","starred_url":"https://api.github.com/users/swankjesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swankjesse/subscriptions","organizations_url":"https://api.github.com/users/swankjesse/orgs","repos_url":"https://api.github.com/users/swankjesse/repos","events_url":"https://api.github.com/users/swankjesse/events{/privacy}","received_events_url":"https://api.github.com/users/swankjesse/received_events","type":"User","site_admin":false},"open_issues":22,"closed_issues":2,"state":"open","created_at":"2014-03-22T02:57:09Z","updated_at":"2015-04-04T02:24:21Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2013-11-12T22:05:17Z","updated_at":"2015-04-18T18:17:48Z","closed_at":null,"body":"The way I'm using retrofit/okhttp most of the requests are POSTs with JSON bodies that aren't huge (2KB - 30KB), but happen fairly frequently.  The server APIs support gzip compressed requests and so I spent some time trying to find a quick way to use gzip compression with retrofit/okhttp and it looks like it wouldn't be possible without modifications to okhttp itself.\r\n\r\nIs there any possibility of this being added or accepted as a pull request?"},"comment":{"url":"https://api.github.com/repos/square/okhttp/issues/comments/94188676","html_url":"https://github.com/square/okhttp/issues/350#issuecomment-94188676","issue_url":"https://api.github.com/repos/square/okhttp/issues/350","id":94188676,"user":{"login":"Gerlot","id":4295130,"avatar_url":"https://avatars.githubusercontent.com/u/4295130?v=3","gravatar_id":"","url":"https://api.github.com/users/Gerlot","html_url":"https://github.com/Gerlot","followers_url":"https://api.github.com/users/Gerlot/followers","following_url":"https://api.github.com/users/Gerlot/following{/other_user}","gists_url":"https://api.github.com/users/Gerlot/gists{/gist_id}","starred_url":"https://api.github.com/users/Gerlot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gerlot/subscriptions","organizations_url":"https://api.github.com/users/Gerlot/orgs","repos_url":"https://api.github.com/users/Gerlot/repos","events_url":"https://api.github.com/users/Gerlot/events{/privacy}","received_events_url":"https://api.github.com/users/Gerlot/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T18:17:48Z","updated_at":"2015-04-18T18:17:48Z","body":"Yeah, I've just figured it out with the help of a partly related conversation:\r\nhttps://github.com/square/okhttp/issues/1349\r\n\r\nMaybe you should add this solution to the linked page about interceptors. It took me 1.5 hour to figure it out.\r\nBtw I did it like this (maybe it will be useful for others):\r\n```java\r\nprivate RequestBody requestBodyWithContentLength(final RequestBody requestBody) throws IOException {\r\n        final Buffer buffer = new Buffer();\r\n        try {\r\n            requestBody.writeTo(buffer);\r\n        } catch (IOException e) {\r\n            throw new IOException(\"Unable to copy RequestBody\");\r\n        }\r\n        return new RequestBody() {\r\n            @Override\r\n            public MediaType contentType() {\r\n                return requestBody.contentType();\r\n            }\r\n\r\n            @Override\r\n            public long contentLength() {\r\n                return buffer.size();\r\n            }\r\n\r\n            @Override\r\n            public void writeTo(BufferedSink sink) throws IOException {\r\n                sink.write(ByteString.read(buffer.inputStream(), (int) buffer.size()));\r\n            }\r\n        };\r\n    }\r\n```\r\nAnd I pass the whole thing to the Request like this:\r\n\r\n```java\r\nRequest compressedRequest = originalRequest.newBuilder()\r\n                .header(\"Content-Encoding\", \"gzip\")\r\n                .method(originalRequest.method(), requestBodyWithContentLength(gzip(originalRequest.body())))\r\n                .build();\r\n```"}}