use of org.apache.http.HeaderElement in project intellij-community by JetBrains.
the class GithubApiUtil method getTokenScopes.
@NotNull
public static Collection<String> getTokenScopes(@NotNull GithubConnection connection) throws IOException {
Header[] headers = connection.headRequest("/user", ACCEPT_V3_JSON);
Header scopesHeader = null;
for (Header header : headers) {
if (header.getName().equals("X-OAuth-Scopes")) {
scopesHeader = header;
break;
}
}
if (scopesHeader == null) {
throw new GithubConfusingException("No scopes header");
}
Collection<String> scopes = new ArrayList<>();
for (HeaderElement elem : scopesHeader.getElements()) {
scopes.add(elem.getName());
}
return scopes;
}
use of org.apache.http.HeaderElement in project robovm by robovm.
the class RFC2965Spec method parse.
@Override
public List<Cookie> parse(final Header header, 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");
}
origin = adjustEffectiveHost(origin);
HeaderElement[] elems = header.getElements();
List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
for (HeaderElement headerelement : elems) {
String name = headerelement.getName();
String value = headerelement.getValue();
if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty");
}
BasicClientCookie cookie;
if (header.getName().equals(SM.SET_COOKIE2)) {
cookie = createCookie2(name, value, origin);
} else {
cookie = createCookie(name, value, origin);
}
// cycle through the parameters
NameValuePair[] attribs = headerelement.getParameters();
// Eliminate duplicate attributes. The first occurrence takes precedence
// See RFC2965: 3.2 Origin Server Role
Map<String, NameValuePair> attribmap = new HashMap<String, NameValuePair>(attribs.length);
for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair param = attribs[j];
attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
}
for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet()) {
NameValuePair attrib = entry.getValue();
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
cookie.setAttribute(s, attrib.getValue());
CookieAttributeHandler handler = findAttribHandler(s);
if (handler != null) {
handler.parse(cookie, attrib.getValue());
}
}
cookies.add(cookie);
}
return cookies;
}
use of org.apache.http.HeaderElement in project robovm by robovm.
the class BestMatchSpec 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");
}
HeaderElement[] helems = header.getElements();
boolean versioned = false;
boolean netscape = false;
for (HeaderElement helem : helems) {
if (helem.getParameterByName("version") != null) {
versioned = true;
}
if (helem.getParameterByName("expires") != null) {
netscape = true;
}
}
if (netscape) {
}
// Do we have a cookie with a version attribute?
if (versioned) {
return getStrict().parse(helems, origin);
} else if (netscape) {
// comma separators
return getNetscape().parse(header, origin);
} else {
return getCompat().parse(helems, origin);
}
}
use of org.apache.http.HeaderElement in project robovm by robovm.
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 XobotOS by xamarin.
the class Headers method parseHeader.
public void parseHeader(CharArrayBuffer buffer) {
int pos = CharArrayBuffers.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