Exemplo n.º 1
0
 /**
  * Prepares the HTTP headers and sends them to the server.
  *
  * <p>For streaming requests with a body, headers must be prepared <strong>before</strong> the
  * output stream has been written to. Otherwise the body would need to be buffered!
  *
  * <p>For non-streaming requests with a body, headers must be prepared <strong>after</strong> the
  * output stream has been written to and closed. This ensures that the {@code Content-Length}
  * header field receives the proper value.
  */
 public void writeRequestHeaders(Request request) throws IOException {
   httpEngine.writingRequestHeaders();
   String requestLine =
       RequestLine.get(
           request,
           httpEngine.getConnection().getRoute().getProxy().type(),
           httpEngine.getConnection().getProtocol());
   httpConnection.writeRequest(request.headers(), requestLine);
 }
  @Override
  public final Map<String, List<String>> getRequestProperties() {
    if (connected) {
      throw new IllegalStateException(
          "Cannot access request header fields after connection is set");
    }

    // For the request line property assigned to the null key, just use no proxy and HTTP 1.1.
    Request request = new Request.Builder().url(getURL()).method(method, null).build();
    String requestLine = RequestLine.get(request, null, 1);
    return OkHeaders.toMultimap(requestHeaders.build(), requestLine);
  }