当前位置: 首页>>代码示例>>Java>>正文


Java Header.getElements方法代码示例

本文整理汇总了Java中org.apache.http.Header.getElements方法的典型用法代码示例。如果您正苦于以下问题:Java Header.getElements方法的具体用法?Java Header.getElements怎么用?Java Header.getElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.Header的用法示例。


在下文中一共展示了Header.getElements方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileNameFromHttpResponse

import org.apache.http.Header; //导入方法依赖的package包/类
public static String getFileNameFromHttpResponse(final HttpResponse response) {
    if (response == null) return null;
    String result = null;
    Header header = response.getFirstHeader("Content-Disposition");
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair fileNamePair = element.getParameterByName("filename");
            if (fileNamePair != null) {
                result = fileNamePair.getValue();
                // try to get correct encoding str
                result = CharsetUtils.toCharset(result, HTTP.UTF_8, result.length());
                break;
            }
        }
    }
    return result;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:18,代码来源:OtherUtils.java

示例2: getCharsetFromHttpResponse

import org.apache.http.Header; //导入方法依赖的package包/类
public static String getCharsetFromHttpResponse(final HttpResponse response) {
    if (response == null) return null;
    String result = null;
    Header header = response.getEntity().getContentType();
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair charsetPair = element.getParameterByName("charset");
            if (charsetPair != null) {
                result = charsetPair.getValue();
                break;
            }
        }
    }

    boolean isSupportedCharset = false;
    if (!TextUtils.isEmpty(result)) {
        try {
            isSupportedCharset = Charset.isSupported(result);
        } catch (Throwable e) {
        }
    }

    return isSupportedCharset ? result : null;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:25,代码来源:OtherUtils.java

示例3: getAllowedMethods

import org.apache.http.Header; //导入方法依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    HeaderIterator it = response.headerIterator("Allow");
    Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        Header header = it.nextHeader();
        HeaderElement[] elements = header.getElements();
        for (HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HttpOptions.java

示例4: parse

import org.apache.http.Header; //导入方法依赖的package包/类
@Override
public List<Cookie> parse(
        final Header header,
        CookieOrigin origin) throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
        throw new MalformedCookieException("Unrecognized cookie header '"
                + header.toString() + "'");
    }
    origin = adjustEffectiveHost(origin);
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, origin);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:RFC2965Spec.java

示例5: inflateGzip

import org.apache.http.Header; //导入方法依赖的package包/类
private void inflateGzip(HttpResponse response, Header encoding) {
    for (HeaderElement element : encoding.getElements()) {
        if (element.getName().equalsIgnoreCase("gzip")) {
            response.setEntity(new GzipInflatingEntity(response.getEntity()));
            return;
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:9,代码来源:RestClient.java

示例6: isEncoded

import org.apache.http.Header; //导入方法依赖的package包/类
/**
 * Returns true if the entity's Content-Type header is
 * <code>application/x-www-form-urlencoded</code>.
 */
public static boolean isEncoded(final HttpEntity entity) {
    Header h = entity.getContentType();
    if (h != null) {
        HeaderElement[] elems = h.getElements();
        if (elems.length > 0) {
            String contentType = elems[0].getName();
            return contentType.equalsIgnoreCase(CONTENT_TYPE);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:19,代码来源:URLEncodedUtils.java

示例7: process

import org.apache.http.Header; //导入方法依赖的package包/类
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    HttpEntity entity = response.getEntity();

    // It wasn't a 304 Not Modified response, 204 No Content or similar
    if (entity != null) {
        Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            HeaderElement[] codecs = ceheader.getElements();
            for (HeaderElement codec : codecs) {
                String codecname = codec.getName().toLowerCase(Locale.US);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    if (context != null) context.setAttribute(UNCOMPRESSED, true);  
                    return;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    if (context != null) context.setAttribute(UNCOMPRESSED, true);
                    return;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:ResponseContentEncoding.java

示例8: isEncoded

import org.apache.http.Header; //导入方法依赖的package包/类
/**
 * Returns true if the entity's Content-Type header is
 * <code>application/x-www-form-urlencoded</code>.
 */
public static boolean isEncoded (final HttpEntity entity) {
    Header h = entity.getContentType();
    if (h != null) {
        HeaderElement[] elems = h.getElements();
        if (elems.length > 0) {
            String contentType = elems[0].getName();
            return contentType.equalsIgnoreCase(CONTENT_TYPE);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:URLEncodedUtils.java

示例9: parse

import org.apache.http.Header; //导入方法依赖的package包/类
public List<Cookie> parse(final Header header, final CookieOrigin origin)
        throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE)) {
        throw new MalformedCookieException("Unrecognized cookie header '"
                + header.toString() + "'");
    }
    HeaderElement[] elems = header.getElements();
    return parse(elems, origin);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:RFC2109Spec.java

示例10: get

import org.apache.http.Header; //导入方法依赖的package包/类
/**
 * Extracts <code>Content-Type</code> value from {@link HttpEntity} exactly as
 * specified by the <code>Content-Type</code> header of the entity. Returns <code>null</code>
 * if not specified.
 *
 * @param entity HTTP entity
 * @return content type
 * @throws ParseException if the given text does not represent a valid
 * <code>Content-Type</code> value.
 */
public static ContentType get(
        final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
    if (entity == null) {
        return null;
    }
    Header header = entity.getContentType();
    if (header != null) {
        HeaderElement[] elements = header.getElements();
        if (elements.length > 0) {
            return create(elements[0]);
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:ContentType.java

示例11: process

import org.apache.http.Header; //导入方法依赖的package包/类
public void process(HttpResponse response, HttpContext context) {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Header encoding = entity.getContentEncoding();
        if (encoding != null) {
            for (HeaderElement element : encoding.getElements()) {
                if (element.getName().equalsIgnoreCase(AsyncHttpClient.ENCODING_GZIP)) {
                    response.setEntity(new AsyncHttpClient$InflatingEntity(entity));
                    return;
                }
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:AsyncHttpClient$2.java

示例12: readHeaders

import org.apache.http.Header; //导入方法依赖的package包/类
private RawHttpHeaders readHeaders(CloseableHttpResponse response) {
    Header[] allHeaders = response.getAllHeaders();
    RawHttpHeaders.Builder headers = RawHttpHeaders.Builder.newBuilder();
    for (Header header : allHeaders) {
        String meta = header.getElements().length > 0 ?
                ";" + Arrays.stream(header.getElements())
                        .flatMap(it -> Arrays.stream(it.getParameters()).map(v -> v.getName() + "=" + v.getValue()))
                        .collect(joining(";")) :
                "";
        headers.with(header.getName(), header.getValue() + meta);
    }
    return headers.build();
}
 
开发者ID:renatoathaydes,项目名称:rawhttp,代码行数:14,代码来源:RawHttpComponentsClient.java

示例13: determineLength

import org.apache.http.Header; //导入方法依赖的package包/类
public long determineLength(final HttpMessage message) throws HttpException {
    if (message == null) {
        throw new IllegalArgumentException("HTTP message may not be null");
    }

    HttpParams params = message.getParams();
    boolean strict = params.isParameterTrue(CoreProtocolPNames.STRICT_TRANSFER_ENCODING);

    Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
    // We use Transfer-Encoding if present and ignore Content-Length.
    // RFC2616, 4.4 item number 3
    if (transferEncodingHeader != null) {
        HeaderElement[] encodings = null;
        try {
            encodings = transferEncodingHeader.getElements();
        } catch (ParseException px) {
            throw new ProtocolException
                ("Invalid Transfer-Encoding header value: " +
                 transferEncodingHeader, px);
        }
        if (strict) {
            // Currently only chunk and identity are supported
            for (int i = 0; i < encodings.length; i++) {
                String encoding = encodings[i].getName();
                if (encoding != null && encoding.length() > 0
                    && !encoding.equalsIgnoreCase(HTTP.CHUNK_CODING)
                    && !encoding.equalsIgnoreCase(HTTP.IDENTITY_CODING)) {
                    throw new ProtocolException("Unsupported transfer encoding: " + encoding);
                }
            }
        }
        // The chunked encoding must be the last one applied RFC2616, 14.41
        int len = encodings.length;
        if (HTTP.IDENTITY_CODING.equalsIgnoreCase(transferEncodingHeader.getValue())) {
            return IDENTITY;
        } else if ((len > 0) && (HTTP.CHUNK_CODING.equalsIgnoreCase(
                encodings[len - 1].getName()))) {
            return CHUNKED;
        } else {
            if (strict) {
                throw new ProtocolException("Chunk-encoding must be the last one applied");
            }
            return IDENTITY;
        }
    }
    Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
    if (contentLengthHeader != null) {
        long contentlen = -1;
        Header[] headers = message.getHeaders(HTTP.CONTENT_LEN);
        if (strict && headers.length > 1) {
            throw new ProtocolException("Multiple content length headers");
        }
        for (int i = headers.length - 1; i >= 0; i--) {
            Header header = headers[i];
            try {
                contentlen = Long.parseLong(header.getValue());
                break;
            } catch (NumberFormatException e) {
                if (strict) {
                    throw new ProtocolException("Invalid content length: " + header.getValue());
                }
            }
            // See if we can have better luck with another header, if present
        }
        if (contentlen >= 0) {
            return contentlen;
        } else {
            return IDENTITY;
        }
    }
    return this.implicitLen;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:73,代码来源:LaxContentLengthStrategy.java


注:本文中的org.apache.http.Header.getElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。