Search in sources :

Example 16 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class DigestScheme method createDigestHeader.

/**
     * 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) throws AuthenticationException {
    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);
}
Also used : BufferedHeader(org.apache.http.message.BufferedHeader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 17 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class BrowserCompatSpec method formatCookies.

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;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 18 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class RFC2109Spec method doFormatOneHeader.

private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
    int version = Integer.MAX_VALUE;
    // Pick the lowest common denominator
    for (Cookie cookie : cookies) {
        if (cookie.getVersion() < version) {
            version = cookie.getVersion();
        }
    }
    CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(version));
    for (Cookie cooky : cookies) {
        buffer.append("; ");
        Cookie cookie = cooky;
        formatCookieAsVer(buffer, cookie, version);
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 19 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class RFC2109Spec method doFormatManyHeaders.

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;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) BufferedHeader(org.apache.http.message.BufferedHeader) ArrayList(java.util.ArrayList) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 20 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project robovm by robovm.

the class DigestScheme method createDigestHeader.

/**
     * 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) throws AuthenticationException {
    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);
}
Also used : BufferedHeader(org.apache.http.message.BufferedHeader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Aggregations

BufferedHeader (org.apache.http.message.BufferedHeader)27 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)27 ArrayList (java.util.ArrayList)15 Header (org.apache.http.Header)12 ClientCookie (org.apache.http.cookie.ClientCookie)12 Cookie (org.apache.http.cookie.Cookie)12 FormattedHeader (org.apache.http.FormattedHeader)6 AuthenticationException (org.apache.http.auth.AuthenticationException)5 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)5 NTCredentials (org.apache.http.auth.NTCredentials)4 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 HttpHost (org.apache.http.HttpHost)1 BasicHeader (org.apache.http.message.BasicHeader)1 GSSContext (org.ietf.jgss.GSSContext)1 GSSException (org.ietf.jgss.GSSException)1 GSSManager (org.ietf.jgss.GSSManager)1 GSSName (org.ietf.jgss.GSSName)1 Oid (org.ietf.jgss.Oid)1