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


Java BasicHeaderValueFormatter类代码示例

本文整理汇总了Java中org.apache.http.message.BasicHeaderValueFormatter的典型用法代码示例。如果您正苦于以下问题:Java BasicHeaderValueFormatter类的具体用法?Java BasicHeaderValueFormatter怎么用?Java BasicHeaderValueFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: formatCookies

import org.apache.http.message.BasicHeaderValueFormatter; //导入依赖的package包/类
@Override
public List<Header> formatCookies(final List<Cookie> cookies) {
    Args.notEmpty(cookies, "List of cookies");
    final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        final Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        final String cookieName = cookie.getName();
        final String cookieValue = cookie.getValue();
        if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) {
            BasicHeaderValueFormatter.INSTANCE.formatHeaderElement(
                    buffer,
                    new BasicHeaderElement(cookieName, cookieValue),
                    false);
        } else {
            // Netscape style cookies do not support quoted values
            buffer.append(cookieName);
            buffer.append("=");
            if (cookieValue != null) {
                buffer.append(cookieValue);
            }
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:BrowserCompatSpec.java

示例2: createDigestHeader

import org.apache.http.message.BasicHeaderValueFormatter; //导入依赖的package包/类
/**
 * Creates digest-response header as defined in RFC2617.
 * 
 * @param credentials User credentials
 * @param digest The response tag's value as String.
 * 
 * @return The digest-response as String.
 */
private Header createDigestHeader(
        final Credentials credentials, 
        final String digest) {
    
    CharArrayBuffer buffer = new CharArrayBuffer(128);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Digest ");
    
    String uri = getParameter("uri");
    String realm = getParameter("realm");
    String nonce = getParameter("nonce");
    String opaque = getParameter("opaque");
    String response = digest;
    String algorithm = getParameter("algorithm");

    String uname = credentials.getUserPrincipal().getName();
    
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(20);
    params.add(new BasicNameValuePair("username", uname));
    params.add(new BasicNameValuePair("realm", realm));
    params.add(new BasicNameValuePair("nonce", nonce));
    params.add(new BasicNameValuePair("uri", uri));
    params.add(new BasicNameValuePair("response", response));
    
    if (qopVariant != QOP_MISSING) {
        params.add(new BasicNameValuePair("qop", getQopVariantString()));
        params.add(new BasicNameValuePair("nc", NC));
        params.add(new BasicNameValuePair("cnonce", getCnonce()));
    }
    if (algorithm != null) {
        params.add(new BasicNameValuePair("algorithm", algorithm));
    }    
    if (opaque != null) {
        params.add(new BasicNameValuePair("opaque", opaque));
    }

    for (int i = 0; i < params.size(); i++) {
        BasicNameValuePair param = params.get(i);
        if (i > 0) {
            buffer.append(", ");
        }
        boolean noQuotes = "nc".equals(param.getName()) ||
                           "qop".equals(param.getName());
        BasicHeaderValueFormatter.DEFAULT
            .formatNameValuePair(buffer, param, !noQuotes);
    }
    return new BufferedHeader(buffer);
}
 
开发者ID:tdopires,项目名称:cJUnit-mc626,代码行数:61,代码来源:DigestScheme.java


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