diff --git a/okhttp/src/main/java/com/squareup/okhttp/Connection.java b/okhttp/src/main/java/com/squareup/okhttp/Connection.java index a6b798da9..a30484515 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Connection.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Connection.java @@ -105,14 +105,9 @@ public final class Connection implements Closeable { if (route.address.sslSocketFactory != null) { upgradeToTls(tunnelRequest); + } else { + streamWrapper(); } - - // Use MTU-sized buffers to send fewer packets. - int mtu = Platform.get().getMtu(socket); - if (mtu < 1024) mtu = 1024; - if (mtu > 8192) mtu = 8192; - in = new BufferedInputStream(in, mtu); - out = new BufferedOutputStream(out, mtu); } /** @@ -152,6 +147,7 @@ public final class Connection implements Closeable { out = sslSocket.getOutputStream(); in = sslSocket.getInputStream(); + streamWrapper(); byte[] selectedProtocol; if (useNpn && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) { @@ -332,4 +328,13 @@ public final class Connection implements Closeable { } } } + + private void streamWrapper() throws IOException { + //Use MTU-sized buffers to send fewer packets. + int mtu = Platform.get().getMtu(socket); + if (mtu < 1024) mtu = 1024; + if (mtu > 8192) mtu = 8192; + in = new BufferedInputStream(in, mtu); + out = new BufferedOutputStream(out, mtu); + } }