title: Retrofit OkHttp unexpected end of stream on Connection error
body: <p>I am using following dependencies (Retrofit and OkHttp).</p>
  
  <pre><code>implementation 'com.squareup.retrofit2:retrofit:2.3.0'
  implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
  implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
  implementation 'com.squareup.okhttp3:okhttp:3.10.0'
  implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
  </code></pre>
  
  <p>Below is my code:</p>
  
  <pre><code>OkHttpClient okHttpClient = new OkHttpClient.Builder()
                  .addInterceptor(cache_interceptor)
                  .cache(cache)
                  .connectTimeout(AppConstants.TIME_OUT, TimeUnit.SECONDS)
                  .readTimeout(AppConstants.TIME_OUT, TimeUnit.SECONDS)
                  .writeTimeout(AppConstants.TIME_OUT, TimeUnit.SECONDS)
                  .connectionSpecs(Collections.singletonList(ConnectionSpec.CLEARTEXT))
                  .retryOnConnectionFailure(false)
                  .build();
  
  return new Retrofit.Builder()
                  .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                  .client(okHttpClient)
                  .addConverterFactory(ScalarsConverterFactory.create())
                  .addConverterFactory(GsonConverterFactory.create())
                  .baseUrl(BuildConfig.BASE_URL).build();
  
  private final Interceptor cache_interceptor = new Interceptor() {
          @Override
          public Response intercept(Chain chain) throws IOException {
  
              Request request = chain.request().newBuilder().addHeader("Connection", "close").build();
              return chain.proceed(request);
          }
      };
  </code></pre>
  
  <blockquote>
    <p>The URL is <strong>https</strong> one, pointing to <strong>AWS S3</strong> instance.</p>
  </blockquote>
  
  <p>But I am getting following error for <code>https</code> URL end point.</p>
  
  <blockquote>
    <p>java.io.IOException: unexpected end of stream on
    Connection{s3.amazonaws.com:443, proxy=DIRECT
    hostAddress=s3.amazonaws.com/XX.XXX.XXX.XX:443 cipherSuite=none
    protocol=http/1.1}</p>
  </blockquote>
  
  <p>Gone through similar threads like <a href="https://github.com/square/okhttp/issues/1517" rel="nofollow noreferrer">Github discussion 1</a>  and <a href="https://github.com/square/okhttp/issues/2738" rel="nofollow noreferrer">Github discussion 2</a>  but could not find a resolution.</p>
  
  <blockquote>
    <p>If I replace <strong>https</strong> with <strong>http</strong> , there is no issue or error as well !!</p>
  </blockquote>
  
  <p><strong>Any idea what might be causing the problem?</strong></p>
  
  <hr>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>As I was not sure what was causing the problem, I just commented out OK Http as client from Retrofit.</p>
  
  <p>And surprisingly error was not thrown. !</p>
  
  <pre><code>return new Retrofit.Builder()
                      .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                      .addConverterFactory(ScalarsConverterFactory.create())
                      .addConverterFactory(GsonConverterFactory.create())
                      .baseUrl(BuildConfig.BASE_URL).build();
  </code></pre>
  
  <p>Anyone wanna contribute to the issue, pls comment or write an answer. Much appreciable!</p>