@Override
  public void handleResponse(RestRequest restRequest, final RestResponseChannel restResponseChannel,
      final ReadableStreamChannel response, Exception exception) throws RestServiceException {
    if (shouldProceed(restRequest, restResponseChannel)) {
      if (exception != null || response == null) {
        onResponseComplete(restResponseChannel, response, exception);
      } else {
        response.readInto(restResponseChannel, new Callback<Long>() {
          private final AtomicBoolean callbackInvoked = new AtomicBoolean(false);

          @Override
          public void onCompletion(Long result, Exception exception) {
            if (callbackInvoked.compareAndSet(false, true)) {
              if (exception == null && (result == null || result != response.getSize())) {
                exception = new IllegalStateException("Response write incomplete");
              }
              onResponseComplete(restResponseChannel, response, exception);
            }
          }
        });
      }
    }
  }
Sends out responses immediately. Returns control only after {@code readableStreamChannel} has been consumed and
sent over the {@code restResponseChannel}.
@param restRequest the {@link RestRequest} for which the response has been constructed.
@param restResponseChannel the {@link RestResponseChannel} to be used to send the response.
@param response a {@link ReadableStreamChannel} that represents the response to the
                               {@code restRequest}.
@param exception if the response could not be constructed, the reason for the failure.
@throws IllegalArgumentException if either of {@code restRequest} or {@code restResponseChannel} is null.
@throws RestServiceException if there is any error while processing the request.
ambry-api/src/test/java/com/github/ambry/rest/MockRestRequestResponseHandler.java