Upgrading OKHTTP to v2.0

-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=71465711
This commit is contained in:
brettmorgan 2014-07-18 16:54:50 -07:00 committed by Eric Anderson
parent 77d9706bd3
commit 56f5ec305e
5 changed files with 32 additions and 25 deletions

View File

@ -34,13 +34,7 @@ public class Http2Request extends Http2Operation implements Request {
for (Map.Entry<String, String> entry : headers.entrySet()) {
requestHeaders.add(new Header(entry.getKey(), entry.getValue()));
}
frameWriter.synStream(false,
false,
getId(),
0,
0,
0,
requestHeaders);
frameWriter.synStream(false, false, getId(), 0, requestHeaders);
} catch (IOException ioe) {
close(new Status(Transport.Code.UNKNOWN, ioe));
}

View File

@ -32,7 +32,7 @@ public class Http2Response extends Http2Operation implements Response {
private Http2Response(int id, FrameWriter frameWriter, Framer framer) {
super(id, frameWriter, framer);
try {
frameWriter.synStream(false, false, getId(), 0, 0, 0, Headers.createResponseHeaders());
frameWriter.synStream(false, false, getId(), 0, Headers.createResponseHeaders());
} catch (IOException ioe) {
close(new Status(Transport.Code.INTERNAL, ioe));
}

View File

@ -21,7 +21,7 @@ import com.squareup.okhttp.internal.spdy.FrameReader;
import com.squareup.okhttp.internal.spdy.FrameWriter;
import com.squareup.okhttp.internal.spdy.Header;
import com.squareup.okhttp.internal.spdy.HeadersMode;
import com.squareup.okhttp.internal.spdy.Http20Draft10;
import com.squareup.okhttp.internal.spdy.Http20Draft12;
import com.squareup.okhttp.internal.spdy.Settings;
import com.squareup.okhttp.internal.spdy.Variant;
@ -94,7 +94,7 @@ public class OkHttpSession implements Session {
*/
private OkHttpSession(Socket socket, RequestRegistry requestRegistry,
Executor executor) throws IOException {
Variant variant = new Http20Draft10();
Variant variant = new Http20Draft12();
// TODO(user): use Okio.buffer(Socket)
countingInputStream = new CountingInputStream(socket.getInputStream());
countingOutputStream = new CountingOutputStream(socket.getOutputStream());
@ -115,7 +115,7 @@ public class OkHttpSession implements Session {
*/
private OkHttpSession(Socket socket, Session server,
RequestRegistry requestRegistry, Executor executor) throws IOException {
Variant variant = new Http20Draft10();
Variant variant = new Http20Draft12();
// TODO(user): use Okio.buffer(Socket)
countingInputStream = new CountingInputStream(socket.getInputStream());
countingOutputStream = new CountingOutputStream(socket.getOutputStream());
@ -252,7 +252,6 @@ public class OkHttpSession implements Session {
boolean inFinished,
int streamId,
int associatedStreamId,
int priority,
List<Header> headers,
HeadersMode headersMode) {
Operation op = getOperation(streamId);
@ -328,7 +327,18 @@ public class OkHttpSession implements Session {
}
@Override
public void priority(int streamId, int priority) {
public void alternateService(int streamId,
String origin,
ByteString protocol,
String host,
int port,
long maxAge) {
// TODO(user): Is this required?
}
@Override
public void priority(int streamId, int streamDependency, int weight, boolean exclusive) {
// noop
}
}

View File

@ -28,11 +28,11 @@ class AsyncFrameWriter implements FrameWriter {
}
@Override
public void connectionHeader() {
public void connectionPreface() {
executor.execute(new WriteRunnable() {
@Override
public void doRun() throws IOException {
frameWriter.connectionHeader();
frameWriter.connectionPreface();
}
});
}
@ -70,13 +70,11 @@ class AsyncFrameWriter implements FrameWriter {
@Override
public void synStream(final boolean outFinished, final boolean inFinished, final int streamId,
final int associatedStreamId, final int priority, final int slot,
final List<Header> headerBlock) {
final int associatedStreamId, final List<Header> headerBlock) {
executor.execute(new WriteRunnable() {
@Override
public void doRun() throws IOException {
frameWriter.synStream(outFinished, inFinished, streamId, associatedStreamId, priority,
slot, headerBlock);
frameWriter.synStream(outFinished, inFinished, streamId, associatedStreamId, headerBlock);
}
});
}

View File

@ -20,7 +20,7 @@ import com.squareup.okhttp.internal.spdy.ErrorCode;
import com.squareup.okhttp.internal.spdy.FrameReader;
import com.squareup.okhttp.internal.spdy.Header;
import com.squareup.okhttp.internal.spdy.HeadersMode;
import com.squareup.okhttp.internal.spdy.Http20Draft10;
import com.squareup.okhttp.internal.spdy.Http20Draft12;
import com.squareup.okhttp.internal.spdy.Settings;
import com.squareup.okhttp.internal.spdy.Variant;
@ -107,7 +107,7 @@ public class OkHttpClientTransport extends AbstractClientTransport {
} catch (IOException e) {
throw new RuntimeException(e);
}
Variant variant = new Http20Draft10();
Variant variant = new Http20Draft12();
frameReader = variant.newReader(source, true);
frameWriter = new AsyncFrameWriter(variant.newWriter(sink, true), this, executor);
@ -222,8 +222,7 @@ public class OkHttpClientTransport extends AbstractClientTransport {
boolean inFinished,
int streamId,
int associatedStreamId,
int priority,
List<Header> headers,
List<Header> headerBlock,
HeadersMode headersMode) {
// TODO(user): handle received headers.
}
@ -273,10 +272,16 @@ public class OkHttpClientTransport extends AbstractClientTransport {
}
@Override
public void priority(int streamId, int priority) {
public void priority(int streamId, int streamDependency, int weight, boolean exclusive) {
// Ignore priority change.
// TODO(user): log
}
@Override
public void alternateService(int streamId, String origin, ByteString protocol, String host,
int port, long maxAge) {
// TODO(user): Deal with alternateService propagation
}
}
/**
@ -294,7 +299,7 @@ public class OkHttpClientTransport extends AbstractClientTransport {
streamId = nextStreamId;
nextStreamId += 2;
streams.put(streamId, this);
frameWriter.synStream(false, false, streamId, 0, 0, 0,
frameWriter.synStream(false, false, streamId, 0,
Headers.createRequestHeaders(method.getName()));
}
deframer = new InputStreamDeframer(inboundMessageHandler());