{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/stetho/issues/220","labels_url":"https://api.github.com/repos/facebook/stetho/issues/220/labels{/name}","comments_url":"https://api.github.com/repos/facebook/stetho/issues/220/comments","events_url":"https://api.github.com/repos/facebook/stetho/issues/220/events","html_url":"https://github.com/facebook/stetho/issues/220","id":94231138,"number":220,"title":"OkHttp StethoInterceptor fails with \"unexpected end of stream\" when uploading \"multipart\" data","user":{"login":"kboyarshinov","id":1917615,"avatar_url":"https://avatars.githubusercontent.com/u/1917615?v=3","gravatar_id":"","url":"https://api.github.com/users/kboyarshinov","html_url":"https://github.com/kboyarshinov","followers_url":"https://api.github.com/users/kboyarshinov/followers","following_url":"https://api.github.com/users/kboyarshinov/following{/other_user}","gists_url":"https://api.github.com/users/kboyarshinov/gists{/gist_id}","starred_url":"https://api.github.com/users/kboyarshinov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kboyarshinov/subscriptions","organizations_url":"https://api.github.com/users/kboyarshinov/orgs","repos_url":"https://api.github.com/users/kboyarshinov/repos","events_url":"https://api.github.com/users/kboyarshinov/events{/privacy}","received_events_url":"https://api.github.com/users/kboyarshinov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-10T06:54:20Z","updated_at":"2015-07-10T14:38:25Z","closed_at":null,"body":"Fails only on POST requests with \"multipart/form-data\" type.\r\n\r\nStacktrace:\r\n```java\r\nretrofit.RetrofitError: unexpected end of stream\r\n            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)\r\n            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)\r\n            at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)\r\n            at retrofit.RxSupport$2.run(RxSupport.java:55)\r\n            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n            at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n            at retrofit.Platform$Android$2$1.run(Platform.java:142)\r\n            at java.lang.Thread.run(Thread.java:818)\r\n     Caused by: java.net.ProtocolException: unexpected end of stream\r\n            at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSink.close(HttpConnection.java:314)\r\n            at okio.RealBufferedSink.close(RealBufferedSink.java:241)\r\n            at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:899)\r\n            at com.facebook.stetho.okhttp.StethoInterceptor.intercept(StethoInterceptor.java:58)\r\n            at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:879)\r\n            at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)\r\n            at com.squareup.okhttp.Call.getResponse(Call.java:274)\r\n            at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)\r\n            at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:227)\r\n            at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)\r\n            at com.squareup.okhttp.Call.execute(Call.java:81)\r\n            at retrofit.client.OkClient.execute(OkClient.java:53)\r\n            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)\r\n            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)\r\n            at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)\r\n            at retrofit.RxSupport$2.run(RxSupport.java:55)\r\n            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n            at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n            at retrofit.Platform$Android$2$1.run(Platform.java:142)\r\n            at java.lang.Thread.run(Thread.java:818)\r\n```\r\n\r\nSimilar issue can be found in okhttp: https://github.com/square/okhttp/issues/1587 with problem and solution described.\r\n\r\nAs I see [`generateBody`](https://github.com/facebook/stetho/blob/master/stetho-okhttp/src/main/java/com/facebook/stetho/okhttp/StethoInterceptor.java#L151) method contains error:\r\n```java\r\n    private byte[] generateBody() throws IOException {\r\n      RequestBody body = mRequest.body();\r\n      if (body == null) {\r\n        return null;\r\n      }\r\n      Buffer buffer = new Buffer();\r\n      body.writeTo(buffer);\r\n      return buffer.readByteArray();\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/facebook/stetho/issues/comments/120424952","html_url":"https://github.com/facebook/stetho/issues/220#issuecomment-120424952","issue_url":"https://api.github.com/repos/facebook/stetho/issues/220","id":120424952,"user":{"login":"jasta","id":83791,"avatar_url":"https://avatars.githubusercontent.com/u/83791?v=3","gravatar_id":"","url":"https://api.github.com/users/jasta","html_url":"https://github.com/jasta","followers_url":"https://api.github.com/users/jasta/followers","following_url":"https://api.github.com/users/jasta/following{/other_user}","gists_url":"https://api.github.com/users/jasta/gists{/gist_id}","starred_url":"https://api.github.com/users/jasta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasta/subscriptions","organizations_url":"https://api.github.com/users/jasta/orgs","repos_url":"https://api.github.com/users/jasta/repos","events_url":"https://api.github.com/users/jasta/events{/privacy}","received_events_url":"https://api.github.com/users/jasta/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T14:38:25Z","updated_at":"2015-07-10T14:38:25Z","body":"I'm not sure that issue applies here directly because we're not actually replacing the request body at all, we're just reading it.  In this case, it actually looks like Stetho's merely in the call stack of another, unrelated issue that is surfaced by the request body declared content length and actual length not matching.\r\n\r\nYou should take a look at what your request body's contentLength() method returns.  If it is not `-1` (as it is by default) then I suspect that's your problem.  If it is `-1`, then I'm curious what specific version of `okhttp` you are using because the code I have for okhttp 2.2.0 indicates clearly that only a positive contentLength() could cause this issue."}}