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


Java Headers.get方法代碼示例

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


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

示例1: 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

示例2: getChartset

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Charset getChartset(RecordedRequest request){
    Headers headers = request.getHeaders();
    String value = headers.get("content-type");
    String[] array = value.split(";");
    Charset charset = null;
    try {
        if(array.length>1&&array[1].startsWith("charset=")){
            String charSetStr = array[1].split("=")[1];
            charset = Charset.forName(charSetStr);
        }
    } catch (Exception e) {
        System.out.println("ContentType:"+value);
        e.printStackTrace();
    }
    if(charset==null){
        charset = Charset.forName("utf-8");
    }
    return charset;
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:20,代碼來源:HttpUtil.java

示例3: parse

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Pagination parse(Headers headers) {
    if (headers == null) {
        return new Pagination();
    }

    String linksString = headers.get(HEADER_KEY_LINK);
    if (TextUtils.isEmpty(linksString)) {
        return new Pagination(null);
    }

    String[] linkStrings = linksString.split(",");
    if (linkStrings.length == 0) {
        return new Pagination(null);
    }

    Link[] links = new Link[linkStrings.length];
    for (int i = 0; i < links.length; i++) {
        Link link = Link.fromSource(linkStrings[i]);
        links[i] = link;
    }

    return new Pagination(links);
}
 
開發者ID:rejasupotaro,項目名稱:octodroid,代碼行數:24,代碼來源:PaginationHeaderParser.java

示例4: createOkBody

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Creates an OkHttp Response.Body containing the supplied information.
 */
private static ResponseBody createOkBody(final Headers okHeaders, InputStream body) {
  final BufferedSource source = Okio.buffer(Okio.source(body));
  return new ResponseBody() {
    @Override public MediaType contentType() {
      String contentTypeHeader = okHeaders.get("Content-Type");
      return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
    }
    @Override public long contentLength() {
      return OkHeaders.contentLength(okHeaders);
    }
    @Override public BufferedSource source() {
      return source;
    }
  };
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:19,代碼來源:JavaApiConverter.java

示例5: createOkBody

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Creates an OkHttp Response.Body containing the supplied information.
 */
private static Response.Body createOkBody(final Headers okHeaders, final InputStream body) {
  return new Response.Body() {

    @Override
    public boolean ready() throws IOException {
      return true;
    }

    @Override
    public MediaType contentType() {
      String contentTypeHeader = okHeaders.get("Content-Type");
      return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
    }

    @Override
    public long contentLength() {
      return OkHeaders.contentLength(okHeaders);
    }

    @Override
    public InputStream byteStream() {
      return body;
    }
  };
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:29,代碼來源:JavaApiConverter.java

示例6: newHttpEngine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private HttpEngine newHttpEngine(String method, StreamAllocation streamAllocation,
                                 RetryableSink requestBody, Response priorResponse) throws
        MalformedURLException, UnknownHostException {
    Request.Builder builder = new Request.Builder().url(Internal.instance.getHttpUrlChecked
            (getURL().toString())).method(method, HttpMethod.requiresRequestBody(method) ?
            EMPTY_REQUEST_BODY : null);
    Headers headers = this.requestHeaders.build();
    int size = headers.size();
    for (int i = 0; i < size; i++) {
        builder.addHeader(headers.name(i), headers.value(i));
    }
    boolean bufferRequestBody = false;
    if (HttpMethod.permitsRequestBody(method)) {
        if (this.fixedContentLength != -1) {
            builder.header("Content-Length", Long.toString(this.fixedContentLength));
        } else if (this.chunkLength > 0) {
            builder.header("Transfer-Encoding", "chunked");
        } else {
            bufferRequestBody = true;
        }
        if (headers.get("Content-Type") == null) {
            builder.header("Content-Type", Client.FormMime);
        }
    }
    if (headers.get(Network.USER_AGENT) == null) {
        builder.header(Network.USER_AGENT, defaultUserAgent());
    }
    Request request = builder.build();
    OkHttpClient engineClient = this.client;
    if (!(Internal.instance.internalCache(engineClient) == null || getUseCaches())) {
        engineClient = this.client.clone().setCache(null);
    }
    return new HttpEngine(engineClient, request, bufferRequestBody, true, false,
            streamAllocation, requestBody, priorResponse);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:36,代碼來源:HttpURLConnectionImpl.java

示例7: combine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Headers combine(Headers paramHeaders1, Headers paramHeaders2)
  throws IOException
{
  Headers.Builder localBuilder = new Headers.Builder();
  int i = 0;
  int j = paramHeaders1.namesAndValues.length / 2;
  while (i < j)
  {
    String str2 = paramHeaders1.name(i);
    String str3 = paramHeaders1.value(i);
    if (((!"Warning".equalsIgnoreCase(str2)) || (!str3.startsWith("1"))) && ((!OkHeaders.isEndToEnd(str2)) || (paramHeaders2.get(str2) == null))) {
      localBuilder.add(str2, str3);
    }
    i++;
  }
  int k = 0;
  int m = paramHeaders2.namesAndValues.length / 2;
  while (k < m)
  {
    String str1 = paramHeaders2.name(k);
    if ((!"Content-Length".equalsIgnoreCase(str1)) && (OkHeaders.isEndToEnd(str1))) {
      localBuilder.add(str1, paramHeaders2.value(k));
    }
    k++;
  }
  return localBuilder.build();
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:28,代碼來源:HttpEngine.java

示例8: create

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Part create(Headers headers, RequestBody body) {
    if (body == null) {
        throw new NullPointerException("body == null");
    }
    if (headers != null && headers.get("Content-Type") != null) {
        throw new IllegalArgumentException("Unexpected header: Content-Type");
    }
    if (headers != null && headers.get("Content-Length") != null) {
        throw new IllegalArgumentException("Unexpected header: Content-Length");
    }
    return new Part(headers, body);
}
 
開發者ID:vector-im,項目名稱:riot-android,代碼行數:13,代碼來源:BugReporterMultipartBody.java

示例9: constructMultipartBody

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private
@Nullable
MultipartBuilder constructMultipartBody(
    ExecutorToken ExecutorToken,
    ReadableArray body,
    String contentType,
    int requestId) {
  MultipartBuilder multipartBuilder = new MultipartBuilder();
  multipartBuilder.type(MediaType.parse(contentType));

  for (int i = 0, size = body.size(); i < size; i++) {
    ReadableMap bodyPart = body.getMap(i);

    // Determine part's content type.
    ReadableArray headersArray = bodyPart.getArray("headers");
    Headers headers = extractHeaders(headersArray, null);
    if (headers == null) {
      onRequestError(
          ExecutorToken,
          requestId,
          "Missing or invalid header format for FormData part.");
      return null;
    }
    MediaType partContentType = null;
    String partContentTypeStr = headers.get(CONTENT_TYPE_HEADER_NAME);
    if (partContentTypeStr != null) {
      partContentType = MediaType.parse(partContentTypeStr);
      // Remove the content-type header because MultipartBuilder gets it explicitly as an
      // argument and doesn't expect it in the headers array.
      headers = headers.newBuilder().removeAll(CONTENT_TYPE_HEADER_NAME).build();
    }

    if (bodyPart.hasKey(REQUEST_BODY_KEY_STRING)) {
      String bodyValue = bodyPart.getString(REQUEST_BODY_KEY_STRING);
      multipartBuilder.addPart(headers, RequestBody.create(partContentType, bodyValue));
    } else if (bodyPart.hasKey(REQUEST_BODY_KEY_URI)) {
      if (partContentType == null) {
        onRequestError(
            ExecutorToken,
            requestId,
            "Binary FormData part needs a content-type header.");
        return null;
      }
      String fileContentUriStr = bodyPart.getString(REQUEST_BODY_KEY_URI);
      InputStream fileInputStream =
          RequestBodyUtil.getFileInputStream(getReactApplicationContext(), fileContentUriStr);
      if (fileInputStream == null) {
        onRequestError(
            ExecutorToken,
            requestId,
            "Could not retrieve file for uri " + fileContentUriStr);
        return null;
      }
      multipartBuilder.addPart(headers, RequestBodyUtil.create(partContentType, fileInputStream));
    } else {
      onRequestError(ExecutorToken, requestId, "Unrecognized FormData part.");
    }
  }
  return multipartBuilder;
}
 
開發者ID:john1jan,項目名稱:ReactNativeSignatureExample,代碼行數:61,代碼來源:NetworkingModule.java

示例10: constructMultipartBody

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private
@Nullable
MultipartBuilder constructMultipartBody(
    ExecutorToken ExecutorToken,
    ReadableArray body,
    String contentType,
    int requestId) {
  MultipartBuilder multipartBuilder = new MultipartBuilder();
  multipartBuilder.type(MediaType.parse(contentType));

  for (int i = 0, size = body.size(); i < size; i++) {
    ReadableMap bodyPart = body.getMap(i);

    // Determine part's content type.
    ReadableArray headersArray = bodyPart.getArray("headers");
    Headers headers = extractHeaders(headersArray, null);
    if (headers == null) {
      onRequestError(
          ExecutorToken,
          requestId,
          "Missing or invalid header format for FormData part.",
          null);
      return null;
    }
    MediaType partContentType = null;
    String partContentTypeStr = headers.get(CONTENT_TYPE_HEADER_NAME);
    if (partContentTypeStr != null) {
      partContentType = MediaType.parse(partContentTypeStr);
      // Remove the content-type header because MultipartBuilder gets it explicitly as an
      // argument and doesn't expect it in the headers array.
      headers = headers.newBuilder().removeAll(CONTENT_TYPE_HEADER_NAME).build();
    }

    if (bodyPart.hasKey(REQUEST_BODY_KEY_STRING)) {
      String bodyValue = bodyPart.getString(REQUEST_BODY_KEY_STRING);
      multipartBuilder.addPart(headers, RequestBody.create(partContentType, bodyValue));
    } else if (bodyPart.hasKey(REQUEST_BODY_KEY_URI)) {
      if (partContentType == null) {
        onRequestError(
            ExecutorToken,
            requestId,
            "Binary FormData part needs a content-type header.",
            null);
        return null;
      }
      String fileContentUriStr = bodyPart.getString(REQUEST_BODY_KEY_URI);
      InputStream fileInputStream =
          RequestBodyUtil.getFileInputStream(getReactApplicationContext(), fileContentUriStr);
      if (fileInputStream == null) {
        onRequestError(
            ExecutorToken,
            requestId,
            "Could not retrieve file for uri " + fileContentUriStr,
            null);
        return null;
      }
      multipartBuilder.addPart(headers, RequestBodyUtil.create(partContentType, fileInputStream));
    } else {
      onRequestError(ExecutorToken, requestId, "Unrecognized FormData part.", null);
    }
  }
  return multipartBuilder;
}
 
開發者ID:ManrajGrover,項目名稱:react-native-box-loaders,代碼行數:64,代碼來源:NetworkingModule.java

示例11: getMimeType

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static String getMimeType(RecordedRequest request){
    Headers headers = request.getHeaders();
    String value = headers.get("content-type");
    String[] array = value.split(";");
    return array[0];
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:7,代碼來源:HttpUtil.java

示例12: bodyEncoded

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private boolean bodyEncoded(Headers headers) {
    String contentEncoding = headers.get("Content-Encoding");
    return contentEncoding != null && !contentEncoding.equalsIgnoreCase("identity");
}
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:5,代碼來源:XgoLogInterceptor.java

示例13: newHttpEngine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private HttpEngine newHttpEngine(String method, Connection connection,
    RetryableSink requestBody, Response priorResponse) {
  Request.Builder builder = new Request.Builder()
      .url(getURL())
      .method(method, null /* No body; that's passed separately. */);
  Headers headers = requestHeaders.build();
  for (int i = 0; i < headers.size(); i++) {
    builder.addHeader(headers.name(i), headers.value(i));
  }

  boolean bufferRequestBody = false;
  if (HttpMethod.hasRequestBody(method)) {
    // Specify how the request body is terminated.
    if (fixedContentLength != -1) {
      builder.header("Content-Length", Long.toString(fixedContentLength));
    } else if (chunkLength > 0) {
      builder.header("Transfer-Encoding", "chunked");
    } else {
      bufferRequestBody = true;
    }

    // Add a content type for the request body, if one isn't already present.
    if (headers.get("Content-Type") == null) {
      builder.header("Content-Type", "application/x-www-form-urlencoded");
    }
  }

  if (headers.get("User-Agent") == null) {
    builder.header("User-Agent", defaultUserAgent());
  }

  Request request = builder.build();

  // If we're currently not using caches, make sure the engine's client doesn't have one.
  OkHttpClient engineClient = client;
  if (Internal.instance.internalCache(engineClient) != null && !getUseCaches()) {
    engineClient = client.clone().setCache(null);
  }

  request = client.preConfigRequest(request);
  return new HttpEngine(engineClient, request, bufferRequestBody, connection, null, requestBody,
      priorResponse);
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:44,代碼來源:HttpURLConnectionImpl.java

示例14: newHttpEngine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private HttpEngine newHttpEngine(String method, Connection connection,
    RetryableSink requestBody, Response priorResponse) {
  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(method)
      ? EMPTY_REQUEST_BODY
      : null;
  Request.Builder builder = new Request.Builder()
      .url(getURL())
      .method(method, placeholderBody);
  Headers headers = requestHeaders.build();
  for (int i = 0, size = headers.size(); i < size; i++) {
    builder.addHeader(headers.name(i), headers.value(i));
  }

  boolean bufferRequestBody = false;
  if (HttpMethod.permitsRequestBody(method)) {
    // Specify how the request body is terminated.
    if (fixedContentLength != -1) {
      builder.header("Content-Length", Long.toString(fixedContentLength));
    } else if (chunkLength > 0) {
      builder.header("Transfer-Encoding", "chunked");
    } else {
      bufferRequestBody = true;
    }

    // Add a content type for the request body, if one isn't already present.
    if (headers.get("Content-Type") == null) {
      builder.header("Content-Type", "application/x-www-form-urlencoded");
    }
  }

  if (headers.get("User-Agent") == null) {
    builder.header("User-Agent", defaultUserAgent());
  }

  Request request = builder.build();

  // If we're currently not using caches, make sure the engine's client doesn't have one.
  OkHttpClient engineClient = client;
  if (Internal.instance.internalCache(engineClient) != null && !getUseCaches()) {
    engineClient = client.clone().setCache(null);
  }

  return new HttpEngine(engineClient, request, bufferRequestBody, true, false, connection, null,
      requestBody, priorResponse);
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:47,代碼來源:HttpURLConnectionImpl.java


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