use of org.apache.http.util.CharArrayBuffer in project android_frameworks_base by crdroidandroid.
the class HttpHeaderTest method testCacheControl.
/**
* Tests that cache control header supports multiple instances of the header,
* according to HTTP specification.
*
* The HTTP specification states the following about the fields:
* Multiple message-header fields with the same field-name MAY be present
* in a message if and only if the entire field-value for that header field
* is defined as a comma-separated list [i.e., #(values)]. It MUST be
* possible to combine the multiple header fields into one "field-name:
* field-value" pair, without changing the semantics of the message, by
* appending each subsequent field-value to the first, each separated by a
* comma. The order in which header fields with the same field-name are
* received is therefore significant to the interpretation of the combined
* field value, and thus a proxy MUST NOT change the order of these field
* values when a message is forwarded.
*/
public void testCacheControl() throws Exception {
Headers h = new Headers();
CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(CACHE_CONTROL_MAX_AGE);
h.parseHeader(buffer);
buffer.clear();
buffer.append(LAST_MODIFIED);
h.parseHeader(buffer);
assertEquals("max-age=15", h.getCacheControl());
buffer.clear();
buffer.append(CACHE_CONTROL_PRIVATE);
h.parseHeader(buffer);
assertEquals("max-age=15,private", h.getCacheControl());
}
use of org.apache.http.util.CharArrayBuffer in project androidquery by androidquery.
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 platform_frameworks_base by android.
the class HttpHeaderTest method testCacheControl.
/**
* Tests that cache control header supports multiple instances of the header,
* according to HTTP specification.
*
* The HTTP specification states the following about the fields:
* Multiple message-header fields with the same field-name MAY be present
* in a message if and only if the entire field-value for that header field
* is defined as a comma-separated list [i.e., #(values)]. It MUST be
* possible to combine the multiple header fields into one "field-name:
* field-value" pair, without changing the semantics of the message, by
* appending each subsequent field-value to the first, each separated by a
* comma. The order in which header fields with the same field-name are
* received is therefore significant to the interpretation of the combined
* field value, and thus a proxy MUST NOT change the order of these field
* values when a message is forwarded.
*/
public void testCacheControl() throws Exception {
Headers h = new Headers();
CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(CACHE_CONTROL_MAX_AGE);
h.parseHeader(buffer);
buffer.clear();
buffer.append(LAST_MODIFIED);
h.parseHeader(buffer);
assertEquals("max-age=15", h.getCacheControl());
buffer.clear();
buffer.append(CACHE_CONTROL_PRIVATE);
h.parseHeader(buffer);
assertEquals("max-age=15,private", h.getCacheControl());
}
use of org.apache.http.util.CharArrayBuffer in project RoboZombie by sahan.
the class URLEncodedUtils method parse.
/**
* Returns a list of {@link NameValuePair NameValuePairs} as deserialized from the given string
* using the given character encoding.
*
* @param s
* text to parse.
* @param charset
* Encoding to use when decoding the parameters.
*
* @since 4.2
*/
public static List<NameValuePair> parse(final String s, final Charset charset) {
if (s == null) {
return Collections.emptyList();
}
BasicHeaderValueParser deserializer = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
ParserCursor cursor = new ParserCursor(0, buffer.length());
List<NameValuePair> list = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
NameValuePair nvp = deserializer.parseNameValuePair(buffer, cursor, DELIM);
if (nvp.getName().length() > 0) {
list.add(new BasicNameValuePair(decodeFormFields(nvp.getName(), charset), decodeFormFields(nvp.getValue(), charset)));
}
}
return list;
}
use of org.apache.http.util.CharArrayBuffer in project XobotOS by xamarin.
the class BasicLineParser method parseHeader.
public static final Header parseHeader(final String value, LineParser parser) throws ParseException {
if (value == null) {
throw new IllegalArgumentException("Value to parse may not be null");
}
if (parser == null)
parser = BasicLineParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
return parser.parseHeader(buffer);
}
Aggregations