/** * Removes all headers named {@code name}, then adds a new header with the * name and value. */ public MockResponse setHeader(String name, Object value) { removeHeader(name); return addHeader(name, value); }
/** * Sets the response body to {@code body}, chunked every {@code maxChunkSize} * bytes. */ public MockResponse setChunkedBody(Buffer body, int maxChunkSize) { removeHeader("Content-Length"); headers.add(CHUNKED_BODY_HEADER); Buffer bytesOut = new Buffer(); while (!body.exhausted()) { long chunkSize = Math.min(body.size(), maxChunkSize); bytesOut.writeHexadecimalUnsignedLong(chunkSize); bytesOut.writeUtf8("\r\n"); bytesOut.write(body, chunkSize); bytesOut.writeUtf8("\r\n"); } bytesOut.writeUtf8("0\r\n\r\n"); // Last chunk + empty trailer + CRLF. this.body = bytesOut; return this; }