本文整理匯總了Java中com.squareup.okhttp.Headers.value方法的典型用法代碼示例。如果您正苦於以下問題:Java Headers.value方法的具體用法?Java Headers.value怎麽用?Java Headers.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.okhttp.Headers
的用法示例。
在下文中一共展示了Headers.value方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toMultimap
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
Map<String, List<String>> result = new TreeMap(FIELD_NAME_COMPARATOR);
int size = headers.size();
for (int i = 0; i < size; i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
List<String> allValues = new ArrayList();
List<String> otherValues = (List) result.get(fieldName);
if (otherValues != null) {
allValues.addAll(otherValues);
}
allValues.add(value);
result.put(fieldName, Collections.unmodifiableList(allValues));
}
if (valueForNullKey != null) {
result.put(null, Collections.unmodifiableList(Collections.singletonList
(valueForNullKey)));
}
return Collections.unmodifiableMap(result);
}
示例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();
}
示例3: TreeMap
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Map<String, List<String>> toMultimap$29224fb9(Headers paramHeaders)
{
TreeMap localTreeMap = new TreeMap(FIELD_NAME_COMPARATOR);
int i = 0;
int j = paramHeaders.namesAndValues.length / 2;
while (i < j)
{
String str1 = paramHeaders.name(i);
String str2 = paramHeaders.value(i);
ArrayList localArrayList = new ArrayList();
List localList = (List)localTreeMap.get(str1);
if (localList != null) {
localArrayList.addAll(localList);
}
localArrayList.add(str2);
localTreeMap.put(str1, Collections.unmodifiableList(localArrayList));
i++;
}
return Collections.unmodifiableMap(localTreeMap);
}
示例4: transformResponse
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例5: transformResponse
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
示例6: toMultimap
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
* Returns an immutable map containing each field to its list of values.
*
* @param valueForNullKey the request line for requests, or the status line
* for responses. If non-null, this value is mapped to the null key.
*/
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
Map<String, List<String>> result = new TreeMap<>(FIELD_NAME_COMPARATOR);
for (int i = 0; i < headers.size(); i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
List<String> allValues = new ArrayList<>();
List<String> otherValues = result.get(fieldName);
if (otherValues != null) {
allValues.addAll(otherValues);
}
allValues.add(value);
result.put(fieldName, Collections.unmodifiableList(allValues));
}
if (valueForNullKey != null) {
result.put(null, Collections.unmodifiableList(Collections.singletonList(valueForNullKey)));
}
return Collections.unmodifiableMap(result);
}
示例7: varyFields
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static Set<String> varyFields(Response response) {
Set<String> result = Collections.emptySet();
Headers headers = response.headers();
for (int i = 0; i < headers.size(); i++) {
if (!"Vary".equalsIgnoreCase(headers.name(i))) continue;
String value = headers.value(i);
if (result.isEmpty()) {
result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
}
for (String varyField : value.split(",")) {
result.add(varyField.trim());
}
}
return result;
}
示例8: toMultimap
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
* Returns an immutable map containing each field to its list of values.
*
* @param valueForNullKey the request line for requests, or the status line
* for responses. If non-null, this value is mapped to the null key.
*/
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
Map<String, List<String>> result = new TreeMap<String, List<String>>(FIELD_NAME_COMPARATOR);
for (int i = 0; i < headers.size(); i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
List<String> allValues = new ArrayList<String>();
List<String> otherValues = result.get(fieldName);
if (otherValues != null) {
allValues.addAll(otherValues);
}
allValues.add(value);
result.put(fieldName, Collections.unmodifiableList(allValues));
}
if (valueForNullKey != null) {
result.put(null, Collections.unmodifiableList(Collections.singletonList(valueForNullKey)));
}
return Collections.unmodifiableMap(result);
}
示例9: parseChallenges
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
List<Challenge> result = new ArrayList();
int size = responseHeaders.size();
for (int i = 0; i < size; i++) {
if (challengeHeader.equalsIgnoreCase(responseHeaders.name(i))) {
String value = responseHeaders.value(i);
int pos = 0;
while (pos < value.length()) {
int tokenStart = pos;
pos = HeaderParser.skipUntil(value, pos, " ");
String scheme = value.substring(tokenStart, pos).trim();
pos = HeaderParser.skipWhitespace(value, pos);
if (!value.regionMatches(true, pos, "realm=\"", 0, "realm=\"".length())) {
break;
}
pos += "realm=\"".length();
int realmStart = pos;
pos = HeaderParser.skipUntil(value, pos, a.e);
String realm = value.substring(realmStart, pos);
pos = HeaderParser.skipWhitespace(value, HeaderParser.skipUntil(value, pos +
1, ",") + 1);
result.add(new Challenge(scheme, realm));
}
}
}
return result;
}
示例10: if
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public CacheStrategy$Factory(long nowMillis, Request request, Response cacheResponse) {
this.nowMillis = nowMillis;
this.request = request;
this.cacheResponse = cacheResponse;
if (cacheResponse != null) {
Headers headers = cacheResponse.headers();
int size = headers.size();
for (int i = 0; i < size; i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
if ("Date".equalsIgnoreCase(fieldName)) {
this.servedDate = HttpDate.parse(value);
this.servedDateString = value;
} else if ("Expires".equalsIgnoreCase(fieldName)) {
this.expires = HttpDate.parse(value);
} else if ("Last-Modified".equalsIgnoreCase(fieldName)) {
this.lastModified = HttpDate.parse(value);
this.lastModifiedString = value;
} else if ("ETag".equalsIgnoreCase(fieldName)) {
this.etag = value;
} else if ("Age".equalsIgnoreCase(fieldName)) {
this.ageSeconds = HeaderParser.parseSeconds(value, -1);
} else if (OkHeaders.SENT_MILLIS.equalsIgnoreCase(fieldName)) {
this.sentRequestMillis = Long.parseLong(value);
} else if (OkHeaders.RECEIVED_MILLIS.equalsIgnoreCase(fieldName)) {
this.receivedResponseMillis = Long.parseLong(value);
}
}
}
}
示例11: parseChallenges
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static List<Challenge> parseChallenges(Headers paramHeaders, String paramString)
{
ArrayList localArrayList = new ArrayList();
int i = 0;
int j = paramHeaders.namesAndValues.length / 2;
while (i < j)
{
if (paramString.equalsIgnoreCase(paramHeaders.name(i)))
{
String str1 = paramHeaders.value(i);
int k = 0;
while (k < str1.length())
{
int m = k;
int n = HeaderParser.skipUntil(str1, k, " ");
String str2 = str1.substring(m, n).trim();
int i1 = HeaderParser.skipWhitespace(str1, n);
if (!str1.regionMatches(true, i1, "realm=\"", 0, 7)) {
break;
}
int i2 = i1 + 7;
int i3 = HeaderParser.skipUntil(str1, i2, "\"");
String str3 = str1.substring(i2, i3);
k = HeaderParser.skipWhitespace(str1, 1 + HeaderParser.skipUntil(str1, i3 + 1, ","));
localArrayList.add(new Challenge(str2, str3));
}
}
i++;
}
return localArrayList;
}
示例12: 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();
}
示例13: Factory
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public Factory(long paramLong, Request paramRequest, Response paramResponse)
{
this.nowMillis = paramLong;
this.request = paramRequest;
this.cacheResponse = paramResponse;
if (paramResponse != null)
{
Headers localHeaders = paramResponse.headers;
int i = 0;
int j = localHeaders.namesAndValues.length / 2;
if (i < j)
{
String str1 = localHeaders.name(i);
String str2 = localHeaders.value(i);
if ("Date".equalsIgnoreCase(str1))
{
this.servedDate = HttpDate.parse(str2);
this.servedDateString = str2;
}
for (;;)
{
i++;
break;
if ("Expires".equalsIgnoreCase(str1))
{
this.expires = HttpDate.parse(str2);
}
else if ("Last-Modified".equalsIgnoreCase(str1))
{
this.lastModified = HttpDate.parse(str2);
this.lastModifiedString = str2;
}
else if ("ETag".equalsIgnoreCase(str1))
{
this.etag = str2;
}
else if ("Age".equalsIgnoreCase(str1))
{
this.ageSeconds = HeaderParser.parseSeconds(str2, -1);
}
else if (OkHeaders.SENT_MILLIS.equalsIgnoreCase(str1))
{
this.sentRequestMillis = Long.parseLong(str2);
}
else if (OkHeaders.RECEIVED_MILLIS.equalsIgnoreCase(str1))
{
this.receivedResponseMillis = Long.parseLong(str2);
}
}
}
}
}
示例14: parseChallenges
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
* Parse RFC 2617 challenges. This API is only interested in the scheme
* name and realm.
*/
public static List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
// auth-scheme = token
// auth-param = token "=" ( token | quoted-string )
// challenge = auth-scheme 1*SP 1#auth-param
// realm = "realm" "=" realm-value
// realm-value = quoted-string
List<Challenge> result = new ArrayList<>();
for (int h = 0; h < responseHeaders.size(); h++) {
if (!challengeHeader.equalsIgnoreCase(responseHeaders.name(h))) {
continue;
}
String value = responseHeaders.value(h);
int pos = 0;
while (pos < value.length()) {
int tokenStart = pos;
pos = HeaderParser.skipUntil(value, pos, " ");
String scheme = value.substring(tokenStart, pos).trim();
pos = HeaderParser.skipWhitespace(value, pos);
// TODO: This currently only handles schemes with a 'realm' parameter;
// It needs to be fixed to handle any scheme and any parameters
// http://code.google.com/p/android/issues/detail?id=11140
if (!value.regionMatches(true, pos, "realm=\"", 0, "realm=\"".length())) {
break; // Unexpected challenge parameter; give up!
}
pos += "realm=\"".length();
int realmStart = pos;
pos = HeaderParser.skipUntil(value, pos, "\"");
String realm = value.substring(realmStart, pos);
pos++; // Consume '"' close quote.
pos = HeaderParser.skipUntil(value, pos, ",");
pos++; // Consume ',' comma.
pos = HeaderParser.skipWhitespace(value, pos);
result.add(new Challenge(scheme, realm));
}
}
return result;
}
示例15: writeNameValueBlock
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
* Returns a list of alternating names and values containing a SPDY request.
* Names are all lowercase. No names are repeated. If any name has multiple
* values, they are concatenated using "\0" as a delimiter.
*/
public static List<Header> writeNameValueBlock(Request request, Protocol protocol,
String version) {
Headers headers = request.headers();
List<Header> result = new ArrayList<>(headers.size() + 10);
result.add(new Header(TARGET_METHOD, request.method()));
result.add(new Header(TARGET_PATH, RequestLine.requestPath(request.url())));
String host = HttpEngine.hostHeader(request.url());
if (Protocol.SPDY_3 == protocol) {
result.add(new Header(VERSION, version));
result.add(new Header(TARGET_HOST, host));
} else if (Protocol.HTTP_2 == protocol) {
result.add(new Header(TARGET_AUTHORITY, host)); // Optional in HTTP/2
} else {
throw new AssertionError();
}
result.add(new Header(TARGET_SCHEME, request.url().getProtocol()));
Set<ByteString> names = new LinkedHashSet<ByteString>();
for (int i = 0; i < headers.size(); i++) {
// header names must be lowercase.
ByteString name = ByteString.encodeUtf8(headers.name(i).toLowerCase(Locale.US));
String value = headers.value(i);
// Drop headers that are forbidden when layering HTTP over SPDY.
if (isProhibitedHeader(protocol, name)) continue;
// They shouldn't be set, but if they are, drop them. We've already written them!
if (name.equals(TARGET_METHOD)
|| name.equals(TARGET_PATH)
|| name.equals(TARGET_SCHEME)
|| name.equals(TARGET_AUTHORITY)
|| name.equals(TARGET_HOST)
|| name.equals(VERSION)) {
continue;
}
// If we haven't seen this name before, add the pair to the end of the list...
if (names.add(name)) {
result.add(new Header(name, value));
continue;
}
// ...otherwise concatenate the existing values and this value.
for (int j = 0; j < result.size(); j++) {
if (result.get(j).name.equals(name)) {
String concatenated = joinOnNull(result.get(j).value.utf8(), value);
result.set(j, new Header(name, concatenated));
break;
}
}
}
return result;
}