Example #1
0
  protected void appendHeaders(Request.Builder builder, Map<String, String> headers) {
    if (builder == null) {
      throw new IllegalArgumentException("builder can not be empty!");
    }

    Headers.Builder headerBuilder = new Headers.Builder();
    if (headers == null || headers.isEmpty()) return;

    for (String key : headers.keySet()) {
      headerBuilder.add(key, headers.get(key));
    }
    builder.headers(headerBuilder.build());
  }
Example #2
0
 private static Headers combine(Headers headers, Headers headers1)
 {
     boolean flag = false;
     com.squareup.okhttp.Headers.Builder builder = new com.squareup.okhttp.Headers.Builder();
     int k = headers.size();
     int j = 0;
     do
     {
         if (j >= k)
         {
             break;
         }
         String s = headers.name(j);
         String s1 = headers.value(j);
         if ((!"Warning".equalsIgnoreCase(s) || !s1.startsWith("1")) && (!OkHeaders.isEndToEnd(s) || headers1.get(s) == null))
         {
             builder.add(s, s1);
         }
         j++;
     } while (true);
     k = headers1.size();
     j = ((flag) ? 1 : 0);
     do
     {
         if (j >= k)
         {
             break;
         }
         headers = headers1.name(j);
         if (!"Content-Length".equalsIgnoreCase(headers) && OkHeaders.isEndToEnd(headers))
         {
             builder.add(headers, headers1.value(j));
         }
         j++;
     } while (true);
     return builder.build();
 }
  @Override
  public final void addRequestProperty(String field, String value) {
    if (connected) {
      throw new IllegalStateException("Cannot add request property after connection is made");
    }
    if (field == null) {
      throw new NullPointerException("field == null");
    }
    if (value == null) {
      // Silently ignore null header values for backwards compatibility with older
      // android versions as well as with other URLConnection implementations.
      //
      // Some implementations send a malformed HTTP header when faced with
      // such requests, we respect the spec and ignore the header.
      Platform.get().logW("Ignoring header " + field + " because its value was null.");
      return;
    }

    if ("X-Android-Transports".equals(field)) {
      setTransports(value, true /* append */);
    } else {
      requestHeaders.add(field, value);
    }
  }