Search in sources :

Example 46 with BasicHeader

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));
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) NetworkResponse(com.android.volley.NetworkResponse) BasicHeader(org.apache.http.message.BasicHeader) Cache(com.android.volley.Cache) Test(org.junit.Test)

Example 47 with BasicHeader

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);
}
Also used : BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) Request(org.apache.http.client.fluent.Request) BasicHeader(org.apache.http.message.BasicHeader) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 48 with BasicHeader

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);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(org.apache.http.client.fluent.Request) BasicHeader(org.apache.http.message.BasicHeader)

Example 49 with BasicHeader

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);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(org.apache.http.client.fluent.Request) BasicHeader(org.apache.http.message.BasicHeader)

Example 50 with BasicHeader

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);
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)128 Header (org.apache.http.Header)67 Test (org.junit.Test)29 List (java.util.List)21 HashMap (java.util.HashMap)19 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicStatusLine (org.apache.http.message.BasicStatusLine)17 ProtocolVersion (org.apache.http.ProtocolVersion)16 StatusLine (org.apache.http.StatusLine)16 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)16 IOException (java.io.IOException)15 HttpURLConnection (java.net.HttpURLConnection)15 URL (java.net.URL)15 HttpResponse (org.apache.http.HttpResponse)15 Response (org.elasticsearch.client.Response)10 ArrayList (java.util.ArrayList)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 TestHttpResponse (org.robolectric.shadows.httpclient.TestHttpResponse)9 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)8 StringEntity (org.apache.http.entity.StringEntity)8