Body delay works for http2 responses only. When used with plain http responses, setBodyDelay acts as one expect setHeadersDelay to act (and setHeadersDelay appears to do nothing).
The following code hangs and times out:
@Test(timeout = 5000)
public void bodyDelayDoesNotWork() throws Exception {
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse()
.setBodyDelay(1, TimeUnit.DAYS)
.setResponseCode(200)
.setBody("Nop"));
HttpURLConnection conn = (HttpURLConnection) server.url("/").url().openConnection();
conn.setDoInput(false);
conn.setDoOutput(false);
conn.setRequestMethod("HEAD");
conn.connect();
Assert.assertEquals(200, conn.getResponseCode());
}
But if you replace .setBodyDelay(1, TimeUnit.DAYS) with .throttleBody(1, 1, TimeUnit.MINUTES), the test passes.
Body delay works for http2 responses only. When used with plain http responses,
setBodyDelayacts as one expectsetHeadersDelayto act (andsetHeadersDelayappears to do nothing).The following code hangs and times out:
But if you replace
.setBodyDelay(1, TimeUnit.DAYS)with.throttleBody(1, 1, TimeUnit.MINUTES), the test passes.