use of okhttp3.internal.http2.StreamResetException in project okhttp by square.
the class DuplexTest method serverCancelsRequestBodyAndSendsResponseBody.
/**
* OkHttp currently doesn't implement failing the request body stream independently of failing the
* corresponding response body stream. This is necessary if we want servers to be able to stop
* inbound data and send an early 400 before the request body completes.
*
* This test sends a slow request that is canceled by the server. It expects the response to still
* be readable after the request stream is canceled.
*/
@Disabled
@Test
public void serverCancelsRequestBodyAndSendsResponseBody() throws Exception {
client = client.newBuilder().retryOnConnectionFailure(false).build();
BlockingQueue<String> log = new LinkedBlockingQueue<>();
enableProtocol(Protocol.HTTP_2);
MockDuplexResponseBody mockDuplexResponseBody = enqueueResponseWithBody(new MockResponse().clearHeaders(), new MockDuplexResponseBody().sendResponse("success!").exhaustResponse().cancelStream(ErrorCode.NO_ERROR));
Call call = client.newCall(new Request.Builder().url(server.url("/")).post(new RequestBody() {
@Override
@Nullable
public MediaType contentType() {
return null;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
try {
for (int i = 0; i < 10; i++) {
sink.writeUtf8(".");
sink.flush();
Thread.sleep(100);
}
} catch (IOException e) {
log.add(e.toString());
throw e;
} catch (Exception e) {
log.add(e.toString());
}
}
}).build());
try (Response response = call.execute()) {
assertThat(response.body().string()).isEqualTo("success!");
}
mockDuplexResponseBody.awaitSuccess();
assertThat(log.take()).contains("StreamResetException: stream was reset: NO_ERROR");
}
use of okhttp3.internal.http2.StreamResetException in project okhttp by square.
the class HttpOverHttp2Test method noRecoveryFromErrorWithRetryDisabled.
private void noRecoveryFromErrorWithRetryDisabled(ErrorCode errorCode) throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.RESET_STREAM_AT_START).setHttp2ErrorCode(errorCode.httpCode));
server.enqueue(new MockResponse().setBody("abc"));
client = client.newBuilder().retryOnConnectionFailure(false).build();
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
try {
call.execute();
fail();
} catch (StreamResetException expected) {
assertEquals(errorCode, expected.errorCode);
}
}
use of okhttp3.internal.http2.StreamResetException in project okhttp by square.
the class StreamAllocation method streamFailed.
public void streamFailed(IOException e) {
Socket socket;
boolean noNewStreams = false;
synchronized (connectionPool) {
if (e instanceof StreamResetException) {
StreamResetException streamResetException = (StreamResetException) e;
if (streamResetException.errorCode == ErrorCode.REFUSED_STREAM) {
refusedStreamCount++;
}
// other errors must be retried on a new connection.
if (streamResetException.errorCode != ErrorCode.REFUSED_STREAM || refusedStreamCount > 1) {
noNewStreams = true;
route = null;
}
} else if (connection != null && (!connection.isMultiplexed() || e instanceof ConnectionShutdownException)) {
noNewStreams = true;
// If this route hasn't completed a call, avoid it for new connections.
if (connection.successCount == 0) {
if (route != null && e != null) {
routeSelector.connectFailed(route, e);
}
route = null;
}
}
socket = deallocate(noNewStreams, false, true);
}
closeQuietly(socket);
}
Aggregations