List of usage examples for com.squareup.okhttp Headers.Builder get
public String get(String name)
From source file:com.facebook.react.modules.network.NetworkingModule.java
License:Open Source License
/** * Extracts the headers from the Array. If the format is invalid, this method will return null. *//*from w w w .j av a 2 s . c o m*/ 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(); }