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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations