Search in sources :

Example 86 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class HttpResponseWriter method writeHeadLine.

protected void writeHeadLine(final HttpMessage message) throws IOException {
    final CharArrayBuffer buffer = lineFormatter.formatStatusLine(this.lineBuf, ((HttpResponse) message).getStatusLine());
    this.sessionBuffer.writeLine(buffer);
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 87 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.

the class BasicHeaderElement method toString.

public String toString() {
    CharArrayBuffer buffer = new CharArrayBuffer(64);
    buffer.append(this.name);
    if (this.value != null) {
        buffer.append("=");
        buffer.append(this.value);
    }
    for (int i = 0; i < this.parameters.length; i++) {
        buffer.append("; ");
        buffer.append(this.parameters[i]);
    }
    return buffer.toString();
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 88 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer 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)

Example 89 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class NTLMScheme method authenticate.

public Header authenticate(final Credentials credentials, final HttpRequest request) throws AuthenticationException {
    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException("Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }
    String response = null;
    if (this.state == State.CHALLENGE_RECEIVED || this.state == State.FAILED) {
        response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getWorkstation());
        this.state = State.MSG_TYPE1_GENERATED;
    } else if (this.state == State.MSG_TYPE2_RECEVIED) {
        response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getWorkstation(), this.challenge);
        this.state = State.MSG_TYPE3_GENERATED;
    } else {
        throw new AuthenticationException("Unexpected state: " + this.state);
    }
    CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": NTLM ");
    buffer.append(response);
    return new BufferedHeader(buffer);
}
Also used : InvalidCredentialsException(org.apache.http.auth.InvalidCredentialsException) AuthenticationException(org.apache.http.auth.AuthenticationException) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) NTCredentials(org.apache.http.auth.NTCredentials)

Example 90 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class BrowserCompatSpec method parse.

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");
    }
    String headervalue = header.getValue();
    boolean isNetscapeCookie = false;
    int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
    if (i1 != -1) {
        i1 += "expires=".length();
        int i2 = headervalue.indexOf(';', i1);
        if (i2 == -1) {
            i2 = headervalue.length();
        }
        try {
            DateUtils.parseDate(headervalue.substring(i1, i2), this.datepatterns);
            isNetscapeCookie = true;
        } catch (DateParseException e) {
        // Does not look like a valid expiry date
        }
    }
    HeaderElement[] elems = null;
    if (isNetscapeCookie) {
        NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
        CharArrayBuffer buffer;
        ParserCursor cursor;
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
        } else {
            String s = header.getValue();
            if (s == null) {
                throw new MalformedCookieException("Header value is null");
            }
            buffer = new CharArrayBuffer(s.length());
            buffer.append(s);
            cursor = new ParserCursor(0, buffer.length());
        }
        elems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
    } else {
        elems = header.getElements();
    }
    return parse(elems, origin);
}
Also used : ParserCursor(org.apache.http.message.ParserCursor) HeaderElement(org.apache.http.HeaderElement) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) FormattedHeader(org.apache.http.FormattedHeader)

Aggregations

CharArrayBuffer (org.apache.http.util.CharArrayBuffer)126 BufferedHeader (org.apache.http.message.BufferedHeader)27 FormattedHeader (org.apache.http.FormattedHeader)24 Header (org.apache.http.Header)21 ArrayList (java.util.ArrayList)19 ClientCookie (org.apache.http.cookie.ClientCookie)12 Cookie (org.apache.http.cookie.Cookie)12 ParserCursor (org.apache.http.message.ParserCursor)11 Headers (android.net.http.Headers)6 IOException (java.io.IOException)6 MalformedChallengeException (org.apache.http.auth.MalformedChallengeException)6 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)6 AuthenticationException (org.apache.http.auth.AuthenticationException)5 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 NTCredentials (org.apache.http.auth.NTCredentials)4 HashMap (java.util.HashMap)3 HeaderElement (org.apache.http.HeaderElement)3 NoHttpResponseException (org.apache.http.NoHttpResponseException)3 ParseException (org.apache.http.ParseException)3