mirror of https://github.com/grpc/grpc-java.git
Upgrading OKHTTP to v2.0
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=71465711
This commit is contained in:
parent
77d9706bd3
commit
56f5ec305e
|
|
@ -34,13 +34,7 @@ public class Http2Request extends Http2Operation implements Request {
|
||||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
requestHeaders.add(new Header(entry.getKey(), entry.getValue()));
|
requestHeaders.add(new Header(entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
frameWriter.synStream(false,
|
frameWriter.synStream(false, false, getId(), 0, requestHeaders);
|
||||||
false,
|
|
||||||
getId(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
requestHeaders);
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
close(new Status(Transport.Code.UNKNOWN, ioe));
|
close(new Status(Transport.Code.UNKNOWN, ioe));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class Http2Response extends Http2Operation implements Response {
|
||||||
private Http2Response(int id, FrameWriter frameWriter, Framer framer) {
|
private Http2Response(int id, FrameWriter frameWriter, Framer framer) {
|
||||||
super(id, frameWriter, framer);
|
super(id, frameWriter, framer);
|
||||||
try {
|
try {
|
||||||
frameWriter.synStream(false, false, getId(), 0, 0, 0, Headers.createResponseHeaders());
|
frameWriter.synStream(false, false, getId(), 0, Headers.createResponseHeaders());
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
close(new Status(Transport.Code.INTERNAL, ioe));
|
close(new Status(Transport.Code.INTERNAL, ioe));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import com.squareup.okhttp.internal.spdy.FrameReader;
|
||||||
import com.squareup.okhttp.internal.spdy.FrameWriter;
|
import com.squareup.okhttp.internal.spdy.FrameWriter;
|
||||||
import com.squareup.okhttp.internal.spdy.Header;
|
import com.squareup.okhttp.internal.spdy.Header;
|
||||||
import com.squareup.okhttp.internal.spdy.HeadersMode;
|
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.Settings;
|
||||||
import com.squareup.okhttp.internal.spdy.Variant;
|
import com.squareup.okhttp.internal.spdy.Variant;
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ public class OkHttpSession implements Session {
|
||||||
*/
|
*/
|
||||||
private OkHttpSession(Socket socket, RequestRegistry requestRegistry,
|
private OkHttpSession(Socket socket, RequestRegistry requestRegistry,
|
||||||
Executor executor) throws IOException {
|
Executor executor) throws IOException {
|
||||||
Variant variant = new Http20Draft10();
|
Variant variant = new Http20Draft12();
|
||||||
// TODO(user): use Okio.buffer(Socket)
|
// TODO(user): use Okio.buffer(Socket)
|
||||||
countingInputStream = new CountingInputStream(socket.getInputStream());
|
countingInputStream = new CountingInputStream(socket.getInputStream());
|
||||||
countingOutputStream = new CountingOutputStream(socket.getOutputStream());
|
countingOutputStream = new CountingOutputStream(socket.getOutputStream());
|
||||||
|
|
@ -115,7 +115,7 @@ public class OkHttpSession implements Session {
|
||||||
*/
|
*/
|
||||||
private OkHttpSession(Socket socket, Session server,
|
private OkHttpSession(Socket socket, Session server,
|
||||||
RequestRegistry requestRegistry, Executor executor) throws IOException {
|
RequestRegistry requestRegistry, Executor executor) throws IOException {
|
||||||
Variant variant = new Http20Draft10();
|
Variant variant = new Http20Draft12();
|
||||||
// TODO(user): use Okio.buffer(Socket)
|
// TODO(user): use Okio.buffer(Socket)
|
||||||
countingInputStream = new CountingInputStream(socket.getInputStream());
|
countingInputStream = new CountingInputStream(socket.getInputStream());
|
||||||
countingOutputStream = new CountingOutputStream(socket.getOutputStream());
|
countingOutputStream = new CountingOutputStream(socket.getOutputStream());
|
||||||
|
|
@ -252,7 +252,6 @@ public class OkHttpSession implements Session {
|
||||||
boolean inFinished,
|
boolean inFinished,
|
||||||
int streamId,
|
int streamId,
|
||||||
int associatedStreamId,
|
int associatedStreamId,
|
||||||
int priority,
|
|
||||||
List<Header> headers,
|
List<Header> headers,
|
||||||
HeadersMode headersMode) {
|
HeadersMode headersMode) {
|
||||||
Operation op = getOperation(streamId);
|
Operation op = getOperation(streamId);
|
||||||
|
|
@ -328,7 +327,18 @@ public class OkHttpSession implements Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
// noop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ class AsyncFrameWriter implements FrameWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectionHeader() {
|
public void connectionPreface() {
|
||||||
executor.execute(new WriteRunnable() {
|
executor.execute(new WriteRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void doRun() throws IOException {
|
public void doRun() throws IOException {
|
||||||
frameWriter.connectionHeader();
|
frameWriter.connectionPreface();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -70,13 +70,11 @@ class AsyncFrameWriter implements FrameWriter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void synStream(final boolean outFinished, final boolean inFinished, final int streamId,
|
public void synStream(final boolean outFinished, final boolean inFinished, final int streamId,
|
||||||
final int associatedStreamId, final int priority, final int slot,
|
final int associatedStreamId, final List<Header> headerBlock) {
|
||||||
final List<Header> headerBlock) {
|
|
||||||
executor.execute(new WriteRunnable() {
|
executor.execute(new WriteRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void doRun() throws IOException {
|
public void doRun() throws IOException {
|
||||||
frameWriter.synStream(outFinished, inFinished, streamId, associatedStreamId, priority,
|
frameWriter.synStream(outFinished, inFinished, streamId, associatedStreamId, headerBlock);
|
||||||
slot, headerBlock);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import com.squareup.okhttp.internal.spdy.ErrorCode;
|
||||||
import com.squareup.okhttp.internal.spdy.FrameReader;
|
import com.squareup.okhttp.internal.spdy.FrameReader;
|
||||||
import com.squareup.okhttp.internal.spdy.Header;
|
import com.squareup.okhttp.internal.spdy.Header;
|
||||||
import com.squareup.okhttp.internal.spdy.HeadersMode;
|
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.Settings;
|
||||||
import com.squareup.okhttp.internal.spdy.Variant;
|
import com.squareup.okhttp.internal.spdy.Variant;
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ public class OkHttpClientTransport extends AbstractClientTransport {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
Variant variant = new Http20Draft10();
|
Variant variant = new Http20Draft12();
|
||||||
frameReader = variant.newReader(source, true);
|
frameReader = variant.newReader(source, true);
|
||||||
frameWriter = new AsyncFrameWriter(variant.newWriter(sink, true), this, executor);
|
frameWriter = new AsyncFrameWriter(variant.newWriter(sink, true), this, executor);
|
||||||
|
|
||||||
|
|
@ -222,8 +222,7 @@ public class OkHttpClientTransport extends AbstractClientTransport {
|
||||||
boolean inFinished,
|
boolean inFinished,
|
||||||
int streamId,
|
int streamId,
|
||||||
int associatedStreamId,
|
int associatedStreamId,
|
||||||
int priority,
|
List<Header> headerBlock,
|
||||||
List<Header> headers,
|
|
||||||
HeadersMode headersMode) {
|
HeadersMode headersMode) {
|
||||||
// TODO(user): handle received headers.
|
// TODO(user): handle received headers.
|
||||||
}
|
}
|
||||||
|
|
@ -273,10 +272,16 @@ public class OkHttpClientTransport extends AbstractClientTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void priority(int streamId, int priority) {
|
public void priority(int streamId, int streamDependency, int weight, boolean exclusive) {
|
||||||
// Ignore priority change.
|
// Ignore priority change.
|
||||||
// TODO(user): log
|
// 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;
|
streamId = nextStreamId;
|
||||||
nextStreamId += 2;
|
nextStreamId += 2;
|
||||||
streams.put(streamId, this);
|
streams.put(streamId, this);
|
||||||
frameWriter.synStream(false, false, streamId, 0, 0, 0,
|
frameWriter.synStream(false, false, streamId, 0,
|
||||||
Headers.createRequestHeaders(method.getName()));
|
Headers.createRequestHeaders(method.getName()));
|
||||||
}
|
}
|
||||||
deframer = new InputStreamDeframer(inboundMessageHandler());
|
deframer = new InputStreamDeframer(inboundMessageHandler());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue