mirror of
https://github.com/square/okhttp.git
synced 2025-08-07 12:42:57 +03:00
Introduces isDuplex method to RequestBody
This commit is contained in:
@@ -26,7 +26,7 @@ import okio.BufferedSink;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
/** A duplex request body that keeps the provided sinks so they can be written to later. */
|
||||
public final class AsyncRequestBody extends RequestBody implements DuplexRequestBody {
|
||||
public final class AsyncRequestBody extends RequestBody {
|
||||
private final BlockingQueue<BufferedSink> requestBodySinks = new LinkedBlockingQueue<>();
|
||||
|
||||
@Override public @Nullable MediaType contentType() {
|
||||
@@ -37,6 +37,10 @@ public final class AsyncRequestBody extends RequestBody implements DuplexRequest
|
||||
requestBodySinks.add(sink);
|
||||
}
|
||||
|
||||
@Override public boolean isDuplex() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public BufferedSink takeSink() throws InterruptedException {
|
||||
BufferedSink result = requestBodySinks.poll(5, TimeUnit.SECONDS);
|
||||
if (result == null) throw new AssertionError("no sink to take");
|
||||
|
Reference in New Issue
Block a user