Java 类org.apache.http.message.BufferedHeader 实例源码

项目:lams    文件:NetscapeDraftSpec.java   
public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:lams    文件:BrowserCompatSpec.java   
public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        buffer.append("=");
        String s = cookie.getValue();
        if (s != null) {
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:PowerApi    文件:HttpUtil.java   
/**
 * 处理返回结果数据
 *
 * @param unitTest
 * @param response
 * @throws IOException
 */
private static void doResponse(UnitTest unitTest, CloseableHttpResponse response) throws IOException {
    int statusCode = response.getStatusLine().getStatusCode();
    unitTest.setResponseCode(statusCode);
    StringBuffer sb = new StringBuffer();
    for (int loop = 0; loop < response.getAllHeaders().length; loop++) {
        BufferedHeader header = (BufferedHeader) response
                .getAllHeaders()[loop];
        if (header.getName().equals("Accept-Charset")) {
            continue;
        }
        sb.append(header.getName() + ":" + header.getValue() + "<br/>");
    }
    unitTest.setResponseHeader(sb.toString());
    HttpEntity entity = response.getEntity();
    String result;
    if (entity != null) {
        result = EntityUtils.toString(entity, "utf-8");
        unitTest.setResponseSize(result.getBytes().length);
        unitTest.setResponseBody(result);
    }
    EntityUtils.consume(entity);
    response.close();
}
项目:diadocsdk-java    文件:DiadocAuthScheme.java   
/**
 * Returns a Diadoc <tt>Authorization</tt> header value for the given
 * {@link DiadocCredentials}.
 *
 * @param credentials The credentials to encode.
 * @return a Diadoc authorization header
 */
public static Header authenticate(final DiadocCredentials credentials) {
    if (credentials == null) {
        throw new IllegalArgumentException("Credentials may not be null");
    }

    StringBuilder sb = new StringBuilder();
    sb.append("ddauth_api_client_id=");
    sb.append(credentials.getApiClientId());
    if (credentials.getAuthToken() != null) {
        sb.append(",ddauth_token=");
        sb.append(credentials.getAuthToken());
    }

    CharArrayBuffer buffer = new CharArrayBuffer(128);
    buffer.append(AUTH.WWW_AUTH_RESP);
    buffer.append(": DiadocAuth ");
    buffer.append(sb.toString());

    return new BufferedHeader(buffer);
}
项目:remote-files-sync    文件:NetscapeDraftSpecHC4.java   
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("; ");
        }
        buffer.append(cookie.getName());
        final String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:purecloud-iot    文件:NetscapeDraftSpec.java   
@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("; ");
        }
        buffer.append(cookie.getName());
        final String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:Visit    文件:NetscapeDraftSpecHC4.java   
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("; ");
        }
        buffer.append(cookie.getName());
        final String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:hawkular-agent    文件:JolokiaClientFactory.java   
@Override
public Header authenticate(Credentials credentials, HttpRequest request, HttpContext context)
        throws AuthenticationException {
    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");

    // the bearer token is stored in the password field, not credentials.getUserPrincipal().getName()
    String bearerToken = credentials.getPassword();

    CharArrayBuffer buffer = new CharArrayBuffer(64);
    if (isProxy()) {
        buffer.append("Proxy-Authorization");
    } else {
        buffer.append("Authorization");
    }
    buffer.append(": Bearer ");
    buffer.append(bearerToken);

    return new BufferedHeader(buffer);
}
项目:cJUnit-mc626    文件:NetscapeDraftSpec.java   
public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:cJUnit-mc626    文件:BrowserCompatSpec.java   
public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        buffer.append("=");
        String s = cookie.getValue();
        if (s != null) {
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:cs-actions    文件:HeadersBuilder.java   
public List<Header> buildHeaders() {
    ArrayList<Header> headersArr = new ArrayList<>();
    if (!StringUtils.isEmpty(headers)) {
        BufferedReader in = new BufferedReader(new StringReader(headers));

        String str;
        try {
            while ((str = in.readLine()) != null) {
                CharArrayBuffer charArrayBuffer = new CharArrayBuffer(str.length());
                charArrayBuffer.append(str);
                headersArr.add(new BufferedHeader(charArrayBuffer));
            }
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
    }

    if (entityContentType != null) {
        headersArr.add(entityContentType);
    } else if (contentType != null && !contentType.toString().isEmpty()) {
        headersArr.add(new BasicHeader("Content-Type", contentType.toString()));
    }
    return headersArr;
}
项目:cs-actions    文件:HeadersBuilderTest.java   
@Test
public void build() {
    ContentType contentType = ContentType.parse(CONTENT_TYPE);
    List<Header> headers = new HeadersBuilder()
            .setHeaders("header1:value1\nheader2:value2")
            .setContentType(contentType)
            .buildHeaders();
    assertEquals(3, headers.size());
    assertThat(headers.get(0), instanceOf(BufferedHeader.class));
    BufferedHeader basicHeader = (BufferedHeader) headers.get(1);
    assertEquals("header2", basicHeader.getName());
    assertEquals("value2", basicHeader.getValue());
    BasicHeader contentTypeHeader = (BasicHeader) headers.get(2);
    assertEquals("Content-Type", contentTypeHeader.getName());
    assertEquals(CONTENT_TYPE, contentTypeHeader.getValue());
}
项目:ZTLib    文件:NetscapeDraftSpecHC4.java   
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("; ");
        }
        buffer.append(cookie.getName());
        final String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:lams    文件:RFC2965Spec.java   
@Override
public Header getVersionHeader() {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
项目:lams    文件:RFC2109Spec.java   
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    List<Header> headers = new ArrayList<Header>(cookies.size());
    for (Cookie cookie : cookies) {
        int version = cookie.getVersion();
        CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
项目:lams    文件:BasicScheme.java   
/**
 * Returns a basic <tt>Authorization</tt> header value for the given
 * {@link Credentials} and charset.
 *
 * @param credentials The credentials to encode.
 * @param charset The charset to use for encoding the credentials
 *
 * @return a basic authorization header
 */
public static Header authenticate(
        final Credentials credentials,
        final String charset,
        boolean proxy) {
    if (credentials == null) {
        throw new IllegalArgumentException("Credentials may not be null");
    }
    if (charset == null) {
        throw new IllegalArgumentException("charset may not be null");
    }

    StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    byte[] base64password = Base64.encodeBase64(
            EncodingUtils.getBytes(tmp.toString(), charset));

    CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:remote-files-sync    文件:RFC2965SpecHC4.java   
@Override
public Header getVersionHeader() {
    final CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
项目:remote-files-sync    文件:RFC2109SpecHC4.java   
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    final List<Header> headers = new ArrayList<Header>(cookies.size());
    for (final Cookie cookie : cookies) {
        final int version = cookie.getVersion();
        final CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
项目:remote-files-sync    文件:BrowserCompatSpecHC4.java   
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)) {
            BasicHeaderValueFormatterHC4.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;
}
项目:remote-files-sync    文件:BasicSchemeHC4.java   
/**
 * Produces basic authorization header for the given set of {@link Credentials}.
 *
 * @param credentials The set of credentials to be used for authentication
 * @param request The request being authenticated
 * @throws org.apache.http.auth.InvalidCredentialsException if authentication
 *   credentials are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a basic authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.decode(
            EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)),
            Base64.NO_WRAP);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:remote-files-sync    文件:BasicSchemeHC4.java   
/**
 * Returns a basic <tt>Authorization</tt> header value for the given
 * {@link Credentials} and charset.
 *
 * @param credentials The credentials to encode.
 * @param charset The charset to use for encoding the credentials
 *
 * @return a basic authorization header
 *
 * @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
 */
@Deprecated
public static Header authenticate(
        final Credentials credentials,
        final String charset,
        final boolean proxy) {
    Args.notNull(credentials, "Credentials");
    Args.notNull(charset, "charset");

    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.encode(
            EncodingUtils.getBytes(tmp.toString(), charset),
            Base64.NO_WRAP);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:purecloud-iot    文件:BrowserCompatSpec.java   
@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;
}
项目:purecloud-iot    文件:RFC2965Spec.java   
@Override
public Header getVersionHeader() {
    final CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
项目:purecloud-iot    文件:RFC2109Spec.java   
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    final List<Header> headers = new ArrayList<Header>(cookies.size());
    for (final Cookie cookie : cookies) {
        final int version = cookie.getVersion();
        final CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
项目:purecloud-iot    文件:BasicScheme.java   
/**
 * Produces basic authorization header for the given set of {@link Credentials}.
 *
 * @param credentials The set of credentials to be used for authentication
 * @param request The request being authenticated
 * @throws org.apache.http.auth.InvalidCredentialsException if authentication
 *   credentials are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a basic authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final Base64 base64codec = new Base64(0);
    final byte[] base64password = base64codec.encode(
            EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)));

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:purecloud-iot    文件:BasicScheme.java   
/**
 * Returns a basic {@code Authorization} header value for the given
 * {@link Credentials} and charset.
 *
 * @param credentials The credentials to encode.
 * @param charset The charset to use for encoding the credentials
 *
 * @return a basic authorization header
 *
 * @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
 */
@Deprecated
public static Header authenticate(
        final Credentials credentials,
        final String charset,
        final boolean proxy) {
    Args.notNull(credentials, "Credentials");
    Args.notNull(charset, "charset");

    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.encodeBase64(
            EncodingUtils.getBytes(tmp.toString(), charset), false);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:purecloud-iot    文件:TestRFC2617Scheme.java   
@Test
public void testProcessChallengeWithLotsOfBlanks() throws Exception {
    final TestAuthScheme authscheme = new TestAuthScheme();
    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    buffer.append(" WWW-Authenticate:    Test       realm=\"realm1\"");
    final Header header = new BufferedHeader(buffer);


    authscheme.processChallenge(header);

    Assert.assertEquals("test", authscheme.getSchemeName());
    Assert.assertEquals("realm1", authscheme.getParameter("realm"));
}
项目:Visit    文件:RFC2965SpecHC4.java   
@Override
public Header getVersionHeader() {
    final CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
项目:Visit    文件:RFC2109SpecHC4.java   
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    final List<Header> headers = new ArrayList<Header>(cookies.size());
    for (final Cookie cookie : cookies) {
        final int version = cookie.getVersion();
        final CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
项目:Visit    文件:BrowserCompatSpecHC4.java   
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)) {
            BasicHeaderValueFormatterHC4.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;
}
项目:Visit    文件:BasicSchemeHC4.java   
/**
 * Produces basic authorization header for the given set of {@link Credentials}.
 *
 * @param credentials The set of credentials to be used for authentication
 * @param request The request being authenticated
 * @throws org.apache.http.auth.InvalidCredentialsException if authentication
 *   credentials are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a basic authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.decode(
            EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)),
            Base64.NO_WRAP);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:Visit    文件:BasicSchemeHC4.java   
/**
 * Returns a basic <tt>Authorization</tt> header value for the given
 * {@link Credentials} and charset.
 *
 * @param credentials The credentials to encode.
 * @param charset The charset to use for encoding the credentials
 *
 * @return a basic authorization header
 *
 * @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
 */
@Deprecated
public static Header authenticate(
        final Credentials credentials,
        final String charset,
        final boolean proxy) {
    Args.notNull(credentials, "Credentials");
    Args.notNull(charset, "charset");

    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.encode(
            EncodingUtils.getBytes(tmp.toString(), charset),
            Base64.NO_WRAP);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:artifactory    文件:BearerScheme.java   
@Override
public Header authenticate(Credentials dummyCredentials, HttpRequest request, HttpContext context)
        throws AuthenticationException {
    TokenProvider tokenProvider = ContextHelper.get().beanForType(TokenProvider.class);
    String token = tokenProvider.getToken(getParameters(),
            request.getRequestLine().getMethod(),
            request.getRequestLine().getUri(),
            realCredentials);
    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    buffer.append(AUTH.WWW_AUTH_RESP);
    buffer.append(": Bearer ");
    buffer.append(token);
    return new BufferedHeader(buffer);
}
项目:cJUnit-mc626    文件:RFC2965Spec.java   
@Override
public Header getVersionHeader() {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
项目:cJUnit-mc626    文件:RFC2109Spec.java   
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    List<Header> headers = new ArrayList<Header>(cookies.size());
    for (Cookie cookie : cookies) {
        int version = cookie.getVersion();
        CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
项目:cJUnit-mc626    文件:BasicScheme.java   
/**
 * Returns a basic <tt>Authorization</tt> header value for the given 
 * {@link Credentials} and charset.
 * 
 * @param credentials The credentials to encode.
 * @param charset The charset to use for encoding the credentials
 * 
 * @return a basic authorization header
 */
public static Header authenticate(
        final Credentials credentials, 
        final String charset, 
        boolean proxy) {
    if (credentials == null) {
        throw new IllegalArgumentException("Credentials may not be null"); 
    }
    if (charset == null) {
        throw new IllegalArgumentException("charset may not be null");
    }

    StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    byte[] base64password = Base64.encodeBase64(
            EncodingUtils.getBytes(tmp.toString(), charset));

    CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
项目:ZTLib    文件:RFC2965SpecHC4.java   
@Override
public Header getVersionHeader() {
    final CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
项目:ZTLib    文件:RFC2109SpecHC4.java   
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
    final List<Header> headers = new ArrayList<Header>(cookies.size());
    for (final Cookie cookie : cookies) {
        final int version = cookie.getVersion();
        final CharArrayBuffer buffer = new CharArrayBuffer(40);
        buffer.append("Cookie: ");
        buffer.append("$Version=");
        buffer.append(Integer.toString(version));
        buffer.append("; ");
        formatCookieAsVer(buffer, cookie, version);
        headers.add(new BufferedHeader(buffer));
    }
    return headers;
}
项目:ZTLib    文件:BrowserCompatSpecHC4.java   
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)) {
            BasicHeaderValueFormatterHC4.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;
}
项目:ZTLib    文件:BasicSchemeHC4.java   
/**
 * Produces basic authorization header for the given set of {@link Credentials}.
 *
 * @param credentials The set of credentials to be used for authentication
 * @param request The request being authenticated
 * @throws org.apache.http.auth.InvalidCredentialsException if authentication
 *   credentials are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a basic authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.decode(
            EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)),
            Base64.NO_WRAP);

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}