use of org.apache.http.message.BasicHeader in project TaEmCasa by Dionen.
the class HttpHeaderParserTest method parseCaseInsensitive.
@Test
public void parseCaseInsensitive() {
long now = System.currentTimeMillis();
Header[] headersArray = new Header[5];
headersArray[0] = new BasicHeader("eTAG", "Yow!");
headersArray[1] = new BasicHeader("DATE", rfc1123Date(now));
headersArray[2] = new BasicHeader("expires", rfc1123Date(now + ONE_HOUR_MILLIS));
headersArray[3] = new BasicHeader("cache-control", "public, max-age=86400");
headersArray[4] = new BasicHeader("content-type", "text/plain");
Map<String, String> headers = BasicNetwork.convertHeaders(headersArray);
NetworkResponse response = new NetworkResponse(0, null, headers, false);
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
assertNotNull(entry);
assertEquals("Yow!", entry.etag);
assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
assertEquals(entry.softTtl, entry.ttl);
assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
}
use of org.apache.http.message.BasicHeader in project gerrit by GerritCodeReview.
the class RestSession method putRaw.
public RestResponse putRaw(String endPoint, RawInput stream) throws IOException {
Preconditions.checkNotNull(stream);
Request put = Request.Put(getUrl(endPoint));
put.addHeader(new BasicHeader("Content-Type", stream.getContentType()));
put.body(new BufferedHttpEntity(new InputStreamEntity(stream.getInputStream(), stream.getContentLength())));
return execute(put);
}
use of org.apache.http.message.BasicHeader in project gerrit by GerritCodeReview.
the class RestSession method postWithHeader.
public RestResponse postWithHeader(String endPoint, Object content, Header header) throws IOException {
Request post = Request.Post(getUrl(endPoint));
if (header != null) {
post.addHeader(header);
}
if (content != null) {
post.addHeader(new BasicHeader("Content-Type", "application/json"));
post.body(new StringEntity(OutputFormat.JSON_COMPACT.newGson().toJson(content), UTF_8));
}
return execute(post);
}
use of org.apache.http.message.BasicHeader in project gerrit by GerritCodeReview.
the class RestSession method putWithHeader.
public RestResponse putWithHeader(String endPoint, Header header, Object content) throws IOException {
Request put = Request.Put(getUrl(endPoint));
if (header != null) {
put.addHeader(header);
}
if (content != null) {
put.addHeader(new BasicHeader("Content-Type", "application/json"));
put.body(new StringEntity(OutputFormat.JSON_COMPACT.newGson().toJson(content), UTF_8));
}
return execute(put);
}
use of org.apache.http.message.BasicHeader in project android_frameworks_base by crdroidandroid.
the class DefaultHttpClientTest method authenticateDigestAlgorithm.
private void authenticateDigestAlgorithm(String algorithm) throws Exception {
String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
DigestScheme digestScheme = new DigestScheme();
digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
HttpGet get = new HttpGet();
digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Aggregations