當前位置: 首頁>>代碼示例>>Java>>正文


Java Headers.Builder方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.Headers.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java Headers.Builder方法的具體用法?Java Headers.Builder怎麽用?Java Headers.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.Headers的用法示例。


在下文中一共展示了Headers.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: appendHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
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());
}
 
開發者ID:dscn,項目名稱:ktball,代碼行數:17,代碼來源:OkHttpRequest.java

示例2: combine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static Headers combine(Headers cachedHeaders, Headers networkHeaders) throws
        IOException {
    int i;
    Headers.Builder result = new Headers.Builder();
    int size = cachedHeaders.size();
    for (i = 0; i < size; i++) {
        String fieldName = cachedHeaders.name(i);
        String value = cachedHeaders.value(i);
        if (!("Warning".equalsIgnoreCase(fieldName) && value.startsWith("1")) && (!OkHeaders
                .isEndToEnd(fieldName) || networkHeaders.get(fieldName) == null)) {
            result.add(fieldName, value);
        }
    }
    size = networkHeaders.size();
    for (i = 0; i < size; i++) {
        fieldName = networkHeaders.name(i);
        if (!"Content-Length".equalsIgnoreCase(fieldName) && OkHeaders.isEndToEnd(fieldName)) {
            result.add(fieldName, networkHeaders.value(i));
        }
    }
    return result.build();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:HttpEngine.java

示例3: readResponse

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public final Response.Builder readResponse()
  throws IOException
{
  if ((this.state != 1) && (this.state != 3)) {
    throw new IllegalStateException("state: " + this.state);
  }
  StatusLine localStatusLine;
  Response.Builder localBuilder;
  do
  {
    localStatusLine = StatusLine.parse(this.source.readUtf8LineStrict());
    localBuilder = new Response.Builder();
    localBuilder.protocol = localStatusLine.protocol;
    localBuilder.code = localStatusLine.code;
    localBuilder.message = localStatusLine.message;
    Headers.Builder localBuilder1 = new Headers.Builder();
    readHeaders(localBuilder1);
    localBuilder1.add(OkHeaders.SELECTED_PROTOCOL, localStatusLine.protocol.toString());
    localBuilder.headers(localBuilder1.build());
  } while (localStatusLine.code == 100);
  this.state = 4;
  return localBuilder;
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:24,代碼來源:HttpConnection.java

示例4: addHeader

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private void addHeader() {
    try {
        URI uri = new URI(url);
        String userInfo = uri.getUserInfo();
        if (userInfo != null) {
            setHeader("Authorization", "Basic " + base64Encode(userInfo));
        }
    } catch (URISyntaxException e) {
        debug(e);
    }

    StringBuilder userAgent = new StringBuilder("BirudoRogu-Android");
    setHeader("User-Agent", userAgent.toString());
    // set headers on request
    Headers.Builder headerBuilder = new Headers.Builder();
    for (String key : header.keySet()) {
        headerBuilder.set(key, header.get(key));
    }
    setHeaders(headerBuilder.build());
}
 
開發者ID:eyedol,項目名稱:birudo,代碼行數:21,代碼來源:BaseHttpClient.java

示例5: varyHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Returns the subset of the headers in {@code response}'s request that
 * impact the content of response's body.
 */
public static Headers varyHeaders(Response response) {
  Set<String> varyFields = varyFields(response);
  if (varyFields.isEmpty()) return new Headers.Builder().build();

  // Use the request headers sent over the network, since that's what the
  // response varies on. Otherwise OkHttp-supplied headers like
  // "Accept-Encoding: gzip" may be lost.
  Headers requestHeaders = response.networkResponse().request().headers();

  Headers.Builder result = new Headers.Builder();
  for (int i = 0; i < requestHeaders.size(); i++) {
    String fieldName = requestHeaders.name(i);
    if (varyFields.contains(fieldName)) {
      result.add(fieldName, requestHeaders.value(i));
    }
  }
  return result.build();
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:23,代碼來源:OkHeaders.java

示例6: readResponse

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/** Parses bytes of a response header from an HTTP transport. */
public Response.Builder readResponse() throws IOException {
  if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) {
    throw new IllegalStateException("state: " + state);
  }

  while (true) {
    StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict());

    Response.Builder responseBuilder = new Response.Builder()
        .protocol(statusLine.protocol)
        .code(statusLine.code)
        .message(statusLine.message);

    Headers.Builder headersBuilder = new Headers.Builder();
    readHeaders(headersBuilder);
    headersBuilder.add(OkHeaders.SELECTED_PROTOCOL, statusLine.protocol.toString());
    responseBuilder.headers(headersBuilder.build());

    if (statusLine.code != HTTP_CONTINUE) {
      state = STATE_OPEN_RESPONSE_BODY;
      return responseBuilder;
    }
  }
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:26,代碼來源:HttpConnection.java

示例7: readChunkSize

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private void readChunkSize() throws IOException {
  // read the suffix of the previous chunk
  if (bytesRemainingInChunk != NO_CHUNK_YET) {
    source.readUtf8LineStrict();
  }
  String chunkSizeString = source.readUtf8LineStrict();
  int index = chunkSizeString.indexOf(";");
  if (index != -1) {
    chunkSizeString = chunkSizeString.substring(0, index);
  }
  try {
    bytesRemainingInChunk = Integer.parseInt(chunkSizeString.trim(), 16);
  } catch (NumberFormatException e) {
    throw new ProtocolException("Expected a hex chunk size but was " + chunkSizeString);
  }
  if (bytesRemainingInChunk == 0) {
    hasMoreChunks = false;
    Headers.Builder trailersBuilder = new Headers.Builder();
    readHeaders(trailersBuilder);
    httpEngine.receiveHeaders(trailersBuilder.build());
    endOfInput(true);
  }
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:24,代碼來源:HttpConnection.java

示例8: extractOkHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Extracts OkHttp headers from the supplied {@link Map}. Only real headers are
 * extracted. Any entry (one with a {@code null} key) is discarded.
 */
// @VisibleForTesting
static Headers extractOkHeaders(Map<String, List<String>> javaHeaders) {
  Headers.Builder okHeadersBuilder = new Headers.Builder();
  for (Map.Entry<String, List<String>> javaHeader : javaHeaders.entrySet()) {
    String name = javaHeader.getKey();
    if (name == null) {
      // The Java API uses the null key to store the status line in responses.
      // Earlier versions of OkHttp would use the null key to store the "request line" in
      // requests. e.g. "GET / HTTP 1.1". Although this is no longer the case it must be
      // explicitly ignored because Headers.Builder does not support null keys.
      continue;
    }
    for (String value : javaHeader.getValue()) {
      okHeadersBuilder.add(name, value);
    }
  }
  return okHeadersBuilder.build();
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:23,代碼來源:JavaApiConverter.java

示例9: readResponse

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/** Parses bytes of a response header from an HTTP transport. */
public Response.Builder readResponse() throws IOException {
  if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) {
    throw new IllegalStateException("state: " + state);
  }

  while (true) {
    String statusLineString = source.readUtf8LineStrict();
    StatusLine statusLine = new StatusLine(statusLineString);

    Response.Builder responseBuilder = new Response.Builder()
        .statusLine(statusLine)
        .header(OkHeaders.SELECTED_PROTOCOL, Protocol.HTTP_11.name.utf8());

    Headers.Builder headersBuilder = new Headers.Builder();
    readHeaders(headersBuilder);
    responseBuilder.headers(headersBuilder.build());

    if (statusLine.code() != HTTP_CONTINUE) {
      state = STATE_OPEN_RESPONSE_BODY;
      return responseBuilder;
    }
  }
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:25,代碼來源:HttpConnection.java

示例10: doCheckHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public FormValidation doCheckHeaders(@QueryParameter String value) {
  if (value.length() > 0) {
    Headers.Builder headers = new Headers.Builder();
    String[] lines = value.split("\r?\n");

    for (String line : lines) {
      int index = line.indexOf(':');
      if (index == -1) {
        return FormValidation.error("Unexpected header: " + line);
      }

      try {
        headers.add(line.substring(0, index).trim(), line.substring(index + 1).trim());
      } catch (Exception e) {
        return FormValidation.error(e.getMessage());
      }
    }
  }

  return FormValidation.ok();
}
 
開發者ID:ChristianBecker,項目名稱:http-post-plugin,代碼行數:22,代碼來源:HttpPostPublisher.java

示例11: varyHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Headers varyHeaders(Headers requestHeaders, Headers responseHeaders) {
    Set<String> varyFields = varyFields(responseHeaders);
    if (varyFields.isEmpty()) {
        return new Headers.Builder().build();
    }
    Headers.Builder result = new Headers.Builder();
    int size = requestHeaders.size();
    for (int i = 0; i < size; i++) {
        String fieldName = requestHeaders.name(i);
        if (varyFields.contains(fieldName)) {
            result.add(fieldName, requestHeaders.value(i));
        }
    }
    return result.build();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:OkHeaders.java

示例12: extractHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Extracts the headers from the Array. If the format is invalid, this method will return null.
 */
private
@Nullable
Headers extractHeaders(
    @Nullable ReadableArray headersArray,
    @Nullable ReadableMap requestData) {
  if (headersArray == null) {
    return null;
  }
  Headers.Builder headersBuilder = new Headers.Builder();
  for (int headersIdx = 0, size = headersArray.size(); headersIdx < size; headersIdx++) {
    ReadableArray header = headersArray.getArray(headersIdx);
    if (header == null || header.size() != 2) {
      return null;
    }
    String headerName = header.getString(0);
    String headerValue = header.getString(1);
    headersBuilder.add(headerName, headerValue);
  }
  if (headersBuilder.get(USER_AGENT_HEADER_NAME) == null && mDefaultUserAgent != null) {
    headersBuilder.add(USER_AGENT_HEADER_NAME, mDefaultUserAgent);
  }

  // Sanitize content encoding header, supported only when request specify payload as string
  boolean isGzipSupported = requestData != null && requestData.hasKey(REQUEST_BODY_KEY_STRING);
  if (!isGzipSupported) {
    headersBuilder.removeAll(CONTENT_ENCODING_HEADER_NAME);
  }

  return headersBuilder.build();
}
 
開發者ID:john1jan,項目名稱:ReactNativeSignatureExample,代碼行數:34,代碼來源:NetworkingModule.java

示例13: appendHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
protected void appendHeaders()
{
    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());
}
 
開發者ID:iQuick,項目名稱:NewsMe,代碼行數:12,代碼來源:OkHttpRequest.java

示例14: createHeader

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
static Headers createHeader(Map<String, List<String>> headers){
    if(headers!=null&&!headers.isEmpty()){
        Headers.Builder hb = new Headers.Builder();
        for(String key:headers.keySet()){
            List<String> values = headers.get(key);
            for(String value:values){
                hb.add(key,value);
            }
        }
        return hb.build();
    }
    return null;
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:14,代碼來源:Ok2Lite.java

示例15: appendHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
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());
}
 
開發者ID:zhangdatao,項目名稱:Emojier-Andriod,代碼行數:14,代碼來源:HttpReuqest.java


注:本文中的com.squareup.okhttp.Headers.Builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。