public static CaseInsensitiveMap<String> extractHeaders(HttpResponse response) {
    final CaseInsensitiveMap<String> headers = new CaseInsensitiveMap<String>();

    for (Header header : response.getAllHeaders()) {
      headers.add(header.getName(), header.getValue());
    }
    return headers;
  }
Example #2
0
 private static void saveHeader(
     final String name, @Nullable final HttpResponse response, final File baseFile) {
   final Header header = response != null ? response.getFirstHeader(name) : null;
   final File file = filenameForHeader(baseFile, name);
   if (header == null) {
     FileUtils.deleteIgnoringFailure(file);
   } else {
     try {
       saveToFile(new ByteArrayInputStream(header.getValue().getBytes("UTF-8")), file);
     } catch (final UnsupportedEncodingException e) {
       // Do not try to display the header in the log message, as our default encoding is
       // likely to be UTF-8 and it will fail as well.
       Log.e("LocalStorage.saveHeader: unable to decode header", e);
     }
   }
 }
Example #3
0
 @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");
   }
   if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
     throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
   }
   origin = adjustEffectiveHost(origin);
   HeaderElement[] elems = header.getElements();
   return createCookies(elems, origin);
 }
 private String getCreds(String password) {
   Header authenticate =
       new BasicAuthHeaderProvider(USERNAME, password).getAuthHeader(null, null, null);
   return authenticate.getValue();
 }