mirror of
https://github.com/square/okhttp.git
synced 2025-12-03 18:31:17 +03:00
Use more convenience methods from Okio 0.8.0.
This commit is contained in:
@@ -717,7 +717,7 @@ public final class MockWebServer {
|
|||||||
}
|
}
|
||||||
BufferedSink sink = Okio.buffer(stream.getSink());
|
BufferedSink sink = Okio.buffer(stream.getSink());
|
||||||
if (response.getThrottleBytesPerPeriod() == Integer.MAX_VALUE) {
|
if (response.getThrottleBytesPerPeriod() == Integer.MAX_VALUE) {
|
||||||
sink.write(body, body.size());
|
sink.writeAll(body);
|
||||||
sink.flush();
|
sink.flush();
|
||||||
} else {
|
} else {
|
||||||
while (body.size() > 0) {
|
while (body.size() > 0) {
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ public class MainTest {
|
|||||||
try {
|
try {
|
||||||
Buffer buffer = new Buffer();
|
Buffer buffer = new Buffer();
|
||||||
body.writeTo(buffer);
|
body.writeTo(buffer);
|
||||||
return new String(buffer.readByteString(buffer.size()).toByteArray(),
|
return buffer.readString(body.contentType().charset());
|
||||||
body.contentType().charset());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,6 +233,6 @@ public class OkApacheClientTest {
|
|||||||
while ((read = in.read(temp)) != -1) {
|
while ((read = in.read(temp)) != -1) {
|
||||||
buffer.write(temp, 0, read);
|
buffer.write(temp, 0, read);
|
||||||
}
|
}
|
||||||
return buffer.readUtf8(buffer.size());
|
return buffer.readUtf8();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ public class RecordingCallback implements Response.Callback {
|
|||||||
Response.Body body = response.body();
|
Response.Body body = response.body();
|
||||||
body.source().readAll(buffer);
|
body.source().readAll(buffer);
|
||||||
|
|
||||||
responses.add(new RecordedResponse(
|
responses.add(new RecordedResponse(response.request(), response, buffer.readUtf8(), null));
|
||||||
response.request(), response, buffer.readUtf8(buffer.size()), null));
|
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,6 @@ public final class RequestTest {
|
|||||||
private String bodyToHex(Request.Body body) throws IOException {
|
private String bodyToHex(Request.Body body) throws IOException {
|
||||||
Buffer buffer = new Buffer();
|
Buffer buffer = new Buffer();
|
||||||
body.writeTo(buffer);
|
body.writeTo(buffer);
|
||||||
return buffer.readByteString(buffer.size()).hex();
|
return buffer.readByteString().hex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class HpackDraft06Test {
|
|||||||
List<Header> headerBlock = headerEntries("cookie", new String(value));
|
List<Header> headerBlock = headerEntries("cookie", new String(value));
|
||||||
|
|
||||||
hpackWriter.writeHeaders(headerBlock);
|
hpackWriter.writeHeaders(headerBlock);
|
||||||
bytesIn.write(bytesOut, bytesOut.size());
|
bytesIn.writeAll(bytesOut);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class HpackDraft06Test {
|
|||||||
out.writeByte(0x0d); // Literal value (len = 13)
|
out.writeByte(0x0d); // Literal value (len = 13)
|
||||||
out.writeUtf8("custom-header");
|
out.writeUtf8("custom-header");
|
||||||
|
|
||||||
bytesIn.write(out, out.size());
|
bytesIn.writeAll(out);
|
||||||
hpackReader.maxHeaderTableByteCount(1);
|
hpackReader.maxHeaderTableByteCount(1);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
@@ -111,7 +111,7 @@ public class HpackDraft06Test {
|
|||||||
out.writeByte(0x0d); // Literal value (len = 13)
|
out.writeByte(0x0d); // Literal value (len = 13)
|
||||||
out.writeUtf8("custom-header");
|
out.writeUtf8("custom-header");
|
||||||
|
|
||||||
bytesIn.write(out, out.size());
|
bytesIn.writeAll(out);
|
||||||
// Set to only support 110 bytes (enough for 2 headers).
|
// Set to only support 110 bytes (enough for 2 headers).
|
||||||
hpackReader.maxHeaderTableByteCount(110);
|
hpackReader.maxHeaderTableByteCount(110);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
@@ -150,7 +150,7 @@ public class HpackDraft06Test {
|
|||||||
out.writeUtf8("custom-header");
|
out.writeUtf8("custom-header");
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesIn.write(out, out.size());
|
bytesIn.writeAll(out);
|
||||||
hpackReader.maxHeaderTableByteCount(16384); // Lots of headers need more room!
|
hpackReader.maxHeaderTableByteCount(16384); // Lots of headers need more room!
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
@@ -173,7 +173,7 @@ public class HpackDraft06Test {
|
|||||||
(byte) 0x25, (byte) 0xba, (byte) 0x7f};
|
(byte) 0x25, (byte) 0xba, (byte) 0x7f};
|
||||||
out.write(huffmanBytes, 0, huffmanBytes.length);
|
out.write(huffmanBytes, 0, huffmanBytes.length);
|
||||||
|
|
||||||
bytesIn.write(out, out.size());
|
bytesIn.writeAll(out);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ public class HpackDraft06Test {
|
|||||||
out.writeByte(0x0d); // Literal value (len = 13)
|
out.writeByte(0x0d); // Literal value (len = 13)
|
||||||
out.writeUtf8("custom-header");
|
out.writeUtf8("custom-header");
|
||||||
|
|
||||||
bytesIn.write(out, out.size());
|
bytesIn.writeAll(out);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ public class HpackDraft06Test {
|
|||||||
hpackWriter.writeHeaders(headerBlock);
|
hpackWriter.writeHeaders(headerBlock);
|
||||||
assertEquals(expectedBytes, bytesOut);
|
assertEquals(expectedBytes, bytesOut);
|
||||||
|
|
||||||
bytesIn.write(bytesOut, bytesOut.size());
|
bytesIn.writeAll(bytesOut);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ public class HpackDraft06Test {
|
|||||||
hpackWriter.writeHeaders(headerBlock);
|
hpackWriter.writeHeaders(headerBlock);
|
||||||
assertEquals(expectedBytes, bytesOut);
|
assertEquals(expectedBytes, bytesOut);
|
||||||
|
|
||||||
bytesIn.write(bytesOut, bytesOut.size());
|
bytesIn.writeAll(bytesOut);
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
|
|
||||||
@@ -431,20 +431,17 @@ public class HpackDraft06Test {
|
|||||||
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06#appendix-D.2
|
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06#appendix-D.2
|
||||||
*/
|
*/
|
||||||
@Test public void readRequestExamplesWithoutHuffman() throws IOException {
|
@Test public void readRequestExamplesWithoutHuffman() throws IOException {
|
||||||
Buffer out = firstRequestWithoutHuffman();
|
bytesIn.writeAll(firstRequestWithoutHuffman());
|
||||||
bytesIn.write(out, out.size());
|
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
checkReadFirstRequestWithoutHuffman();
|
checkReadFirstRequestWithoutHuffman();
|
||||||
|
|
||||||
out = secondRequestWithoutHuffman();
|
bytesIn.writeAll(secondRequestWithoutHuffman());
|
||||||
bytesIn.write(out, out.size());
|
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
checkReadSecondRequestWithoutHuffman();
|
checkReadSecondRequestWithoutHuffman();
|
||||||
|
|
||||||
out = thirdRequestWithoutHuffman();
|
bytesIn.writeAll(thirdRequestWithoutHuffman());
|
||||||
bytesIn.write(out, out.size());
|
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
checkReadThirdRequestWithoutHuffman();
|
checkReadThirdRequestWithoutHuffman();
|
||||||
@@ -634,20 +631,17 @@ public class HpackDraft06Test {
|
|||||||
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06#appendix-D.3
|
* http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06#appendix-D.3
|
||||||
*/
|
*/
|
||||||
@Test public void readRequestExamplesWithHuffman() throws IOException {
|
@Test public void readRequestExamplesWithHuffman() throws IOException {
|
||||||
Buffer out = firstRequestWithHuffman();
|
bytesIn.writeAll(firstRequestWithHuffman());
|
||||||
bytesIn.write(out, out.size());
|
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
checkReadFirstRequestWithHuffman();
|
checkReadFirstRequestWithHuffman();
|
||||||
|
|
||||||
out = secondRequestWithHuffman();
|
bytesIn.writeAll(secondRequestWithHuffman());
|
||||||
bytesIn.write(out, out.size());
|
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
checkReadSecondRequestWithHuffman();
|
checkReadSecondRequestWithHuffman();
|
||||||
|
|
||||||
out = thirdRequestWithHuffman();
|
bytesIn.writeAll(thirdRequestWithHuffman());
|
||||||
bytesIn.write(out, out.size());
|
|
||||||
hpackReader.readHeaders();
|
hpackReader.readHeaders();
|
||||||
hpackReader.emitReferenceSet();
|
hpackReader.emitReferenceSet();
|
||||||
checkReadThirdRequestWithHuffman();
|
checkReadThirdRequestWithHuffman();
|
||||||
@@ -928,6 +922,7 @@ public class HpackDraft06Test {
|
|||||||
|
|
||||||
private void assertBytes(int... bytes) {
|
private void assertBytes(int... bytes) {
|
||||||
ByteString expected = intArrayToByteArray(bytes);
|
ByteString expected = intArrayToByteArray(bytes);
|
||||||
|
// TODO change to bytesOut.readByteString() once Okio 0.8.1+ is available.
|
||||||
ByteString actual = bytesOut.readByteString(bytesOut.size());
|
ByteString actual = bytesOut.readByteString(bytesOut.size());
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(Http20Draft10.TYPE_HEADERS);
|
frame.writeByte(Http20Draft10.TYPE_HEADERS);
|
||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_END_STREAM);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_END_STREAM);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.write(headerBytes, headerBytes.size());
|
frame.writeAll(headerBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -106,7 +106,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PRIORITY);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PRIORITY);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeInt(0); // Highest priority is 0.
|
frame.writeInt(0); // Highest priority is 0.
|
||||||
frame.write(headerBytes, headerBytes.size());
|
frame.writeAll(headerBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -149,7 +149,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(Http20Draft10.TYPE_CONTINUATION);
|
frame.writeByte(Http20Draft10.TYPE_CONTINUATION);
|
||||||
frame.writeByte(FLAG_END_HEADERS);
|
frame.writeByte(FLAG_END_HEADERS);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -191,7 +191,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(Http20Draft10.FLAG_END_PUSH_PROMISE);
|
frame.writeByte(Http20Draft10.FLAG_END_PUSH_PROMISE);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeInt(expectedPromisedStreamId & 0x7fffffff);
|
frame.writeInt(expectedPromisedStreamId & 0x7fffffff);
|
||||||
frame.write(headerBytes, headerBytes.size());
|
frame.writeAll(headerBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -557,7 +557,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(paddingLength);
|
frame.writeShort(paddingLength);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
frame.write(padding);
|
frame.write(padding);
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -574,7 +574,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(0);
|
frame.writeShort(0);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
fr.nextFrame(assertHeaderBlock());
|
fr.nextFrame(assertHeaderBlock());
|
||||||
@@ -589,7 +589,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeByte(0);
|
frame.writeByte(0);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
fr.nextFrame(assertHeaderBlock());
|
fr.nextFrame(assertHeaderBlock());
|
||||||
@@ -608,7 +608,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_PAD_HIGH);
|
frame.writeByte(FLAG_PAD_HIGH);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(paddingLength);
|
frame.writeShort(paddingLength);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
frame.write(padding);
|
frame.write(padding);
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -636,7 +636,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(0xffff);
|
frame.writeShort(0xffff);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
frame.write(padding);
|
frame.write(padding);
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -676,7 +676,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(paddingLength);
|
frame.writeShort(paddingLength);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
frame.write(padding);
|
frame.write(padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,7 +703,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_HIGH | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(0);
|
frame.writeShort(0);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -728,7 +728,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_LOW);
|
frame.writeByte(FLAG_END_HEADERS | FLAG_PAD_LOW);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeByte(0);
|
frame.writeByte(0);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
FrameReader fr = new Http20Draft10.Reader(frame, 4096, false);
|
||||||
@@ -757,7 +757,7 @@ public class Http20Draft10Test {
|
|||||||
frame.writeByte(FLAG_PAD_HIGH);
|
frame.writeByte(FLAG_PAD_HIGH);
|
||||||
frame.writeInt(expectedStreamId & 0x7fffffff);
|
frame.writeInt(expectedStreamId & 0x7fffffff);
|
||||||
frame.writeShort(paddingLength);
|
frame.writeShort(paddingLength);
|
||||||
frame.write(headerBlock, headerBlock.size());
|
frame.writeAll(headerBlock);
|
||||||
frame.write(padding);
|
frame.write(padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,7 +807,7 @@ public class Http20Draft10Test {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
assertEquals("PROTOCOL_ERROR padding > 16383: 65535", e.getMessage());
|
assertEquals("PROTOCOL_ERROR padding > 16383: 65535", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void tooLargeDataFrame() throws IOException {
|
@Test public void tooLargeDataFrame() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public final class MockSpdyPeer implements Closeable {
|
|||||||
FrameReader reader = variant.newReader(Okio.buffer(Okio.source(in)), client);
|
FrameReader reader = variant.newReader(Okio.buffer(Okio.source(in)), client);
|
||||||
|
|
||||||
Iterator<OutFrame> outFramesIterator = outFrames.iterator();
|
Iterator<OutFrame> outFramesIterator = outFrames.iterator();
|
||||||
byte[] outBytes = bytesOut.readByteString(bytesOut.size()).toByteArray();
|
byte[] outBytes = bytesOut.readByteArray();
|
||||||
OutFrame nextOutFrame = null;
|
OutFrame nextOutFrame = null;
|
||||||
|
|
||||||
for (int i = 0; i < frameCount; i++) {
|
for (int i = 0; i < frameCount; i++) {
|
||||||
|
|||||||
@@ -1547,10 +1547,7 @@ public final class SpdyConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertStreamData(String expected, Source source) throws IOException {
|
private void assertStreamData(String expected, Source source) throws IOException {
|
||||||
Buffer buffer = new Buffer();
|
String actual = Okio.buffer(source).readUtf8();
|
||||||
while (source.read(buffer, Long.MAX_VALUE) != -1) {
|
|
||||||
}
|
|
||||||
String actual = buffer.readUtf8(buffer.size());
|
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import java.io.Reader;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import okio.Buffer;
|
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
|
|
||||||
import static com.squareup.okhttp.internal.Util.UTF_8;
|
import static com.squareup.okhttp.internal.Util.UTF_8;
|
||||||
@@ -199,26 +198,17 @@ public final class Response {
|
|||||||
throw new IOException("Cannot buffer entire body for content length: " + contentLength);
|
throw new IOException("Cannot buffer entire body for content length: " + contentLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO once https://github.com/square/okio/pull/41 is released.
|
|
||||||
// byte[] bytes = source.readByteArray();
|
|
||||||
// if (contentLength != -1 && contentLength != bytes.length) {
|
|
||||||
// throw new IOException("Content-Length and stream length disagree");
|
|
||||||
// }
|
|
||||||
// return bytes;
|
|
||||||
|
|
||||||
BufferedSource source = source();
|
BufferedSource source = source();
|
||||||
Buffer buffer = new Buffer();
|
byte[] bytes;
|
||||||
long contentRead;
|
|
||||||
try {
|
try {
|
||||||
contentRead = buffer.writeAll(source);
|
bytes = source.readByteArray();
|
||||||
} finally {
|
} finally {
|
||||||
Util.closeQuietly(source);
|
Util.closeQuietly(source);
|
||||||
}
|
}
|
||||||
if (contentLength != -1 && contentLength != contentRead) {
|
if (contentLength != -1 && contentLength != bytes.length) {
|
||||||
throw new IOException("Content-Length and stream length disagree");
|
throw new IOException("Content-Length and stream length disagree");
|
||||||
}
|
}
|
||||||
|
return bytes;
|
||||||
return buffer.readByteArray(buffer.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -367,6 +367,7 @@ public class Platform {
|
|||||||
result.writeByte(protocol.toString().length());
|
result.writeByte(protocol.toString().length());
|
||||||
result.writeUtf8(protocol.toString());
|
result.writeUtf8(protocol.toString());
|
||||||
}
|
}
|
||||||
|
// TODO change to result.readByteArray() when Okio 0.8.1+ is available.
|
||||||
return result.readByteArray(result.size());
|
return result.readByteArray(result.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,6 @@ public final class RetryableSink implements Sink {
|
|||||||
|
|
||||||
public void writeToSocket(BufferedSink socketOut) throws IOException {
|
public void writeToSocket(BufferedSink socketOut) throws IOException {
|
||||||
// Clone the content; otherwise we won't have data to retry.
|
// Clone the content; otherwise we won't have data to retry.
|
||||||
socketOut.write(content.clone(), content.size());
|
socketOut.writeAll(content.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ public final class Http20Draft10 implements Variant {
|
|||||||
byte flags = FLAG_END_HEADERS;
|
byte flags = FLAG_END_HEADERS;
|
||||||
frameHeader(streamId, length, type, flags); // TODO: CONTINUATION
|
frameHeader(streamId, length, type, flags); // TODO: CONTINUATION
|
||||||
sink.writeInt(promisedStreamId & 0x7fffffff);
|
sink.writeInt(promisedStreamId & 0x7fffffff);
|
||||||
sink.write(hpackBuffer, hpackBuffer.size());
|
sink.writeAll(hpackBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void headers(boolean outFinished, int streamId, int priority,
|
private void headers(boolean outFinished, int streamId, int priority,
|
||||||
@@ -414,7 +414,7 @@ public final class Http20Draft10 implements Variant {
|
|||||||
if (priority != -1) length += 4;
|
if (priority != -1) length += 4;
|
||||||
frameHeader(streamId, length, type, flags); // TODO: CONTINUATION
|
frameHeader(streamId, length, type, flags); // TODO: CONTINUATION
|
||||||
if (priority != -1) sink.writeInt(priority & 0x7fffffff);
|
if (priority != -1) sink.writeInt(priority & 0x7fffffff);
|
||||||
sink.write(hpackBuffer, hpackBuffer.size());
|
sink.writeAll(hpackBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public synchronized void rstStream(int streamId, ErrorCode errorCode)
|
@Override public synchronized void rstStream(int streamId, ErrorCode errorCode)
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ public final class Spdy3 implements Variant {
|
|||||||
sink.writeInt(streamId & 0x7fffffff);
|
sink.writeInt(streamId & 0x7fffffff);
|
||||||
sink.writeInt(associatedStreamId & 0x7fffffff);
|
sink.writeInt(associatedStreamId & 0x7fffffff);
|
||||||
sink.writeShort((priority & 0x7) << 13 | (unused & 0x1f) << 8 | (slot & 0xff));
|
sink.writeShort((priority & 0x7) << 13 | (unused & 0x1f) << 8 | (slot & 0xff));
|
||||||
sink.write(headerBlockBuffer, headerBlockBuffer.size());
|
sink.writeAll(headerBlockBuffer);
|
||||||
sink.flush();
|
sink.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ public final class Spdy3 implements Variant {
|
|||||||
sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
|
sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
|
||||||
sink.writeInt((flags & 0xff) << 24 | length & 0xffffff);
|
sink.writeInt((flags & 0xff) << 24 | length & 0xffffff);
|
||||||
sink.writeInt(streamId & 0x7fffffff);
|
sink.writeInt(streamId & 0x7fffffff);
|
||||||
sink.write(headerBlockBuffer, headerBlockBuffer.size());
|
sink.writeAll(headerBlockBuffer);
|
||||||
sink.flush();
|
sink.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +371,7 @@ public final class Spdy3 implements Variant {
|
|||||||
sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
|
sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
|
||||||
sink.writeInt((flags & 0xff) << 24 | length & 0xffffff);
|
sink.writeInt((flags & 0xff) << 24 | length & 0xffffff);
|
||||||
sink.writeInt(streamId & 0x7fffffff);
|
sink.writeInt(streamId & 0x7fffffff);
|
||||||
sink.write(headerBlockBuffer, headerBlockBuffer.size());
|
sink.writeAll(headerBlockBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public synchronized void rstStream(int streamId, ErrorCode errorCode)
|
@Override public synchronized void rstStream(int streamId, ErrorCode errorCode)
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ public final class SpdyStream {
|
|||||||
// Move the received data to the read buffer to the reader can read it.
|
// Move the received data to the read buffer to the reader can read it.
|
||||||
synchronized (SpdyStream.this) {
|
synchronized (SpdyStream.this) {
|
||||||
boolean wasEmpty = readBuffer.size() == 0;
|
boolean wasEmpty = readBuffer.size() == 0;
|
||||||
readBuffer.write(receiveBuffer, receiveBuffer.size());
|
readBuffer.writeAll(receiveBuffer);
|
||||||
if (wasEmpty) {
|
if (wasEmpty) {
|
||||||
SpdyStream.this.notifyAll();
|
SpdyStream.this.notifyAll();
|
||||||
}
|
}
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
<!-- Compilation -->
|
<!-- Compilation -->
|
||||||
<java.version>1.6</java.version>
|
<java.version>1.6</java.version>
|
||||||
<okio.version>0.7.0</okio.version>
|
<okio.version>0.8.0</okio.version>
|
||||||
<!-- Targetted to jdk7u60-b13; Oracle jdk7u55-b13. -->
|
<!-- Targetted to jdk7u60-b13; Oracle jdk7u55-b13. -->
|
||||||
<npn.version>1.1.7.v20140316</npn.version>
|
<npn.version>1.1.7.v20140316</npn.version>
|
||||||
<bouncycastle.version>1.48</bouncycastle.version>
|
<bouncycastle.version>1.48</bouncycastle.version>
|
||||||
|
|||||||
Reference in New Issue
Block a user