use of org.apache.http.HeaderElement in project platform_external_apache-http by android.
the class RFC2617Scheme method parseChallenge.
@Override
protected void parseChallenge(final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException {
HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
ParserCursor cursor = new ParserCursor(pos, buffer.length());
HeaderElement[] elements = parser.parseElements(buffer, cursor);
if (elements.length == 0) {
throw new MalformedChallengeException("Authentication challenge is empty");
}
this.params = new HashMap<String, String>(elements.length);
for (HeaderElement element : elements) {
this.params.put(element.getName(), element.getValue());
}
}
use of org.apache.http.HeaderElement in project platform_external_apache-http by android.
the class HttpOptions method getAllowedMethods.
public Set<String> getAllowedMethods(final HttpResponse response) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderIterator it = response.headerIterator("Allow");
Set<String> methods = new HashSet<String>();
while (it.hasNext()) {
Header header = it.nextHeader();
HeaderElement[] elements = header.getElements();
for (HeaderElement element : elements) {
methods.add(element.getName());
}
}
return methods;
}
use of org.apache.http.HeaderElement in project platform_external_apache-http by android.
the class BasicHeaderElementIterator method nextElement.
public HeaderElement nextElement() throws NoSuchElementException {
if (this.currentElement == null) {
parseNextElement();
}
if (this.currentElement == null) {
throw new NoSuchElementException("No more header elements available");
}
HeaderElement element = this.currentElement;
this.currentElement = null;
return element;
}
use of org.apache.http.HeaderElement in project platform_external_apache-http by android.
the class BasicHeaderElementIterator method parseNextElement.
private void parseNextElement() {
// loop while there are headers left to parse
while (this.headerIt.hasNext() || this.cursor != null) {
if (this.cursor == null || this.cursor.atEnd()) {
// get next header value
bufferHeaderValue();
}
// Anything buffered?
if (this.cursor != null) {
// loop while there is data in the buffer
while (!this.cursor.atEnd()) {
HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor);
if (!(e.getName().length() == 0 && e.getValue() == null)) {
// Found something
this.currentElement = e;
return;
}
}
// if at the end of the buffer
if (this.cursor.atEnd()) {
// discard it
this.cursor = null;
this.buffer = null;
}
}
}
}
use of org.apache.http.HeaderElement in project platform_external_apache-http by android.
the class Headers method parseHeader.
public void parseHeader(CharArrayBuffer buffer) {
int pos = setLowercaseIndexOf(buffer, ':');
if (pos == -1) {
return;
}
String name = buffer.substringTrimmed(0, pos);
if (name.length() == 0) {
return;
}
pos++;
String val = buffer.substringTrimmed(pos, buffer.length());
if (HttpLog.LOGV) {
HttpLog.v("hdr " + buffer.length() + " " + buffer);
}
switch(name.hashCode()) {
case HASH_TRANSFER_ENCODING:
if (name.equals(TRANSFER_ENCODING)) {
mHeaders[IDX_TRANSFER_ENCODING] = val;
HeaderElement[] encodings = BasicHeaderValueParser.DEFAULT.parseElements(buffer, new ParserCursor(pos, buffer.length()));
// The chunked encoding must be the last one applied RFC2616,
// 14.41
int len = encodings.length;
if (HTTP.IDENTITY_CODING.equalsIgnoreCase(val)) {
transferEncoding = ContentLengthStrategy.IDENTITY;
} else if ((len > 0) && (HTTP.CHUNK_CODING.equalsIgnoreCase(encodings[len - 1].getName()))) {
transferEncoding = ContentLengthStrategy.CHUNKED;
} else {
transferEncoding = ContentLengthStrategy.IDENTITY;
}
}
break;
case HASH_CONTENT_LEN:
if (name.equals(CONTENT_LEN)) {
mHeaders[IDX_CONTENT_LEN] = val;
try {
contentLength = Long.parseLong(val);
} catch (NumberFormatException e) {
if (false) {
Log.v(LOGTAG, "Headers.headers(): error parsing" + " content length: " + buffer.toString());
}
}
}
break;
case HASH_CONTENT_TYPE:
if (name.equals(CONTENT_TYPE)) {
mHeaders[IDX_CONTENT_TYPE] = val;
}
break;
case HASH_CONTENT_ENCODING:
if (name.equals(CONTENT_ENCODING)) {
mHeaders[IDX_CONTENT_ENCODING] = val;
}
break;
case HASH_CONN_DIRECTIVE:
if (name.equals(CONN_DIRECTIVE)) {
mHeaders[IDX_CONN_DIRECTIVE] = val;
setConnectionType(buffer, pos);
}
break;
case HASH_LOCATION:
if (name.equals(LOCATION)) {
mHeaders[IDX_LOCATION] = val;
}
break;
case HASH_PROXY_CONNECTION:
if (name.equals(PROXY_CONNECTION)) {
mHeaders[IDX_PROXY_CONNECTION] = val;
setConnectionType(buffer, pos);
}
break;
case HASH_WWW_AUTHENTICATE:
if (name.equals(WWW_AUTHENTICATE)) {
mHeaders[IDX_WWW_AUTHENTICATE] = val;
}
break;
case HASH_PROXY_AUTHENTICATE:
if (name.equals(PROXY_AUTHENTICATE)) {
mHeaders[IDX_PROXY_AUTHENTICATE] = val;
}
break;
case HASH_CONTENT_DISPOSITION:
if (name.equals(CONTENT_DISPOSITION)) {
mHeaders[IDX_CONTENT_DISPOSITION] = val;
}
break;
case HASH_ACCEPT_RANGES:
if (name.equals(ACCEPT_RANGES)) {
mHeaders[IDX_ACCEPT_RANGES] = val;
}
break;
case HASH_EXPIRES:
if (name.equals(EXPIRES)) {
mHeaders[IDX_EXPIRES] = val;
}
break;
case HASH_CACHE_CONTROL:
if (name.equals(CACHE_CONTROL)) {
// This should be ok, according to RFC 2616 chapter 4.2
if (mHeaders[IDX_CACHE_CONTROL] != null && mHeaders[IDX_CACHE_CONTROL].length() > 0) {
mHeaders[IDX_CACHE_CONTROL] += (',' + val);
} else {
mHeaders[IDX_CACHE_CONTROL] = val;
}
}
break;
case HASH_LAST_MODIFIED:
if (name.equals(LAST_MODIFIED)) {
mHeaders[IDX_LAST_MODIFIED] = val;
}
break;
case HASH_ETAG:
if (name.equals(ETAG)) {
mHeaders[IDX_ETAG] = val;
}
break;
case HASH_SET_COOKIE:
if (name.equals(SET_COOKIE)) {
mHeaders[IDX_SET_COOKIE] = val;
cookies.add(val);
}
break;
case HASH_PRAGMA:
if (name.equals(PRAGMA)) {
mHeaders[IDX_PRAGMA] = val;
}
break;
case HASH_REFRESH:
if (name.equals(REFRESH)) {
mHeaders[IDX_REFRESH] = val;
}
break;
case HASH_X_PERMITTED_CROSS_DOMAIN_POLICIES:
if (name.equals(X_PERMITTED_CROSS_DOMAIN_POLICIES)) {
mHeaders[IDX_X_PERMITTED_CROSS_DOMAIN_POLICIES] = val;
}
break;
default:
mExtraHeaderNames.add(name);
mExtraHeaderValues.add(val);
}
}
Aggregations