@Override public MockResponse peek() { MockResponse peek = responseQueue.peek(); if (peek != null) return peek; if (failFastResponse != null) return failFastResponse; return super.peek(); }
private void acceptConnections() throws Exception { while (true) { Socket socket; try { socket = serverSocket.accept(); } catch (SocketException e) { logger.info(MockWebServer.this + " done accepting connections: " + e.getMessage()); return; } SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (socketPolicy == DISCONNECT_AT_START) { dispatchBookkeepingRequest(0, socket); socket.close(); } else { openClientSockets.add(socket); serveConnection(socket); } } } });
/** * Respond to CONNECT requests until a SWITCH_TO_SSL_AT_END response is * dispatched. */ private void createTunnel() throws IOException, InterruptedException { BufferedSource source = Okio.buffer(Okio.source(raw)); BufferedSink sink = Okio.buffer(Okio.sink(raw)); while (true) { SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (!processOneRequest(raw, source, sink)) { throw new IllegalStateException("Tunnel without any CONNECT!"); } if (socketPolicy == UPGRADE_TO_SSL_AT_END) return; } }
final SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (expectContinue && socketPolicy == EXPECT_CONTINUE || socketPolicy == CONTINUE_ALWAYS) { sink.writeUtf8("HTTP/1.1 100 Continue\r\n"); TruncatingBuffer requestBody = new TruncatingBuffer(bodyLimit); List<Integer> chunkSizes = new ArrayList<>(); MockResponse policy = dispatcher.peek(); if (contentLength != -1) { hasBody = contentLength > 0;
@Override public void onStream(Http2Stream stream) throws IOException { MockResponse peekedResponse = dispatcher.peek(); if (peekedResponse.getSocketPolicy() == RESET_STREAM_AT_START) { try {
public void processConnection() throws Exception { SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); Protocol protocol = Protocol.HTTP_1_1; Socket socket;
MockResponse peek = dispatcher.peek(); if (peek.isDuplex()) { readBody = false;
@Override public MockResponse peek() { MockResponse peek = responseQueue.peek(); if (peek != null) return peek; if (failFastResponse != null) return failFastResponse; return super.peek(); }
private void acceptConnections() throws Exception { while (true) { Socket socket; try { socket = serverSocket.accept(); } catch (SocketException e) { logger.info(MockWebServer.this + " done accepting connections: " + e.getMessage()); return; } SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (socketPolicy == DISCONNECT_AT_START) { dispatchBookkeepingRequest(0, socket); socket.close(); } else { openClientSockets.add(socket); serveConnection(socket); } } } });
/** * Respond to CONNECT requests until a SWITCH_TO_SSL_AT_END response is * dispatched. */ private void createTunnel() throws IOException, InterruptedException { BufferedSource source = Okio.buffer(Okio.source(raw)); BufferedSink sink = Okio.buffer(Okio.sink(raw)); while (true) { SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (!processOneRequest(raw, source, sink)) { throw new IllegalStateException("Tunnel without any CONNECT!"); } if (socketPolicy == UPGRADE_TO_SSL_AT_END) return; } }
if (expectContinue && dispatcher.peek().getSocketPolicy() == EXPECT_CONTINUE) { sink.writeUtf8("HTTP/1.1 100 Continue\r\n"); sink.writeUtf8("Content-Length: 0\r\n"); TruncatingBuffer requestBody = new TruncatingBuffer(bodyLimit); List<Integer> chunkSizes = new ArrayList<>(); MockResponse policy = dispatcher.peek(); if (contentLength != -1) { hasBody = contentLength > 0;
@Override public void onStream(Http2Stream stream) throws IOException { MockResponse peekedResponse = dispatcher.peek(); if (peekedResponse.getSocketPolicy() == RESET_STREAM_AT_START) { try {
createTunnel(); SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy(); if (socketPolicy == FAIL_HANDSHAKE) { dispatchBookkeepingRequest(sequenceNumber, raw);
MockResponse peek = dispatcher.peek(); if (!readBody && peek.getSocketPolicy() == EXPECT_CONTINUE) { stream.sendResponseHeaders(Collections.singletonList(