Android BasicHttpRequest - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BasicHttpRequest class.

This code example shows how to use the following methods:getParams, getRequestLine
            // expected 
        } 
    } 
 
    public void testRequestLine() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/stuff");
        request.getParams().setParameter(
                CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
        assertEquals("GET", request.getRequestLine().getMethod());
        assertEquals("/stuff", request.getRequestLine().getUri());
        assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getProtocolVersion());
    } 
 
    public void testRequestLine2() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_0);
        assertEquals("GET", request.getRequestLine().getMethod());
        assertEquals("/stuff", request.getRequestLine().getUri());
        assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getProtocolVersion());
    } 
 
6
CodeRank
This code example shows how to use the following methods:addHeader, getHeaders, getParams
        Assert.assertNull(header1);
    } 
 
    @Test 
    public void testDefaultHeaders() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("custom", "stuff");
        List<Header> defheaders = new ArrayList<Header>();
        defheaders.add(new BasicHeader("custom", "more stuff"));
        request.getParams().setParameter(AllClientPNames.DEFAULT_HEADERS, defheaders);
        HttpContext context = new BasicHttpContext();
 
        HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
        interceptor.process(request, context);
        Header[] headers = request.getHeaders("custom");
        Assert.assertNotNull(headers);
        Assert.assertEquals(2, headers.length);
        Assert.assertEquals("stuff", headers[0].getValue());
        Assert.assertEquals("more stuff", headers[1].getValue());
    } 
6
CodeRank
This code example shows how to use the following methods:addHeader
 
        conn.bind(socket);
 
        Assert.assertEquals(0, conn.getMetrics().getRequestCount());
 
        final HttpRequest request = new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_1);
        request.addHeader("User-Agent", "test");
 
        conn.sendRequestHeader(request);
        conn.flush();
 
        Assert.assertEquals(1, conn.getMetrics().getRequestCount());
        final String s = new String(outstream.toByteArray(), "ASCII");
        Assert.assertEquals("GET /stuff HTTP/1.1\r\nUser-Agent: test\r\n\r\n", s);
    } 
 
    @Test 
    public void testWriteResponseEntity() throws Exception { 
        final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        Mockito.when(socket.getOutputStream()).thenReturn(outstream);
6
CodeRank
This code example shows how to use the following methods:addHeader, getFirstHeader
        Assert.assertEquals("gzip,deflate", header.getValue());
    } 
 
    @Test 
    public void testAcceptEncodingAlreadyPResent() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader("Accept-Encoding", "stuff");
        HttpContext context = new BasicHttpContext();
 
        HttpRequestInterceptor interceptor = new RequestAcceptEncoding();
        interceptor.process(request, context);
        Header header = request.getFirstHeader("Accept-Encoding");
        Assert.assertNotNull(header);
        Assert.assertEquals("stuff", header.getValue());
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:addHeader
        request.addHeader("Cache-Control", "no-store");
        request.addHeader("Cache-Control", "max-age=20");
 
        Assert.assertFalse(policy.isServableFromCache(request));
 
        request = new BasicHttpRequest("GET", "someUri");
        request.addHeader("Cache-Control", "public");
        request.addHeader("Cache-Control", "no-store, max-age=20");
 
        Assert.assertFalse(policy.isServableFromCache(request));
    } 
 
    @Test 
    public void testIsGetWithPragmaServableFromCache() { 
        BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
        request.addHeader("Pragma", "no-cache");
 
        Assert.assertFalse(policy.isServableFromCache(request));
 
        request = new BasicHttpRequest("GET", "someUri");
6
CodeRank
This code example shows how to use the following methods:addHeader
        request.addHeader("Cache-Control", "no-store");
        request.addHeader("Cache-Control", "max-age=20");
 
        Assert.assertFalse(policy.isServableFromCache(request));
 
        request = new BasicHttpRequest("GET", "someUri");
        request.addHeader("Cache-Control", "public");
        request.addHeader("Cache-Control", "no-store, max-age=20");
 
        Assert.assertFalse(policy.isServableFromCache(request));
    } 
 
    @Test 
    public void testIsGetWithPragmaServableFromCache() { 
        BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
        request.addHeader("Pragma", "no-cache");
 
        Assert.assertFalse(policy.isServableFromCache(request));
 
        request = new BasicHttpRequest("GET", "someUri");
6
CodeRank
This code example shows how to use the following methods:addHeader, getFirstHeader
        Assert.assertNull(header2);
    } 
 
    @Test 
    public void testPreserveCustomConnectionHeader() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        HttpContext context = new BasicHttpContext();
 
        HttpHost target = new HttpHost("localhost", 443, "https");
        HttpHost proxy = new HttpHost("localhost", 8080);
        HttpRoute route = new HttpRoute(target, null, proxy, true,
                TunnelType.TUNNELLED, LayerType.LAYERED);
 
        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
 
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
 
        HttpRequestInterceptor interceptor = new RequestClientConnControl();

5
CodeRank
This code example shows how to use the following methods:addHeader, getFirstHeader
        Assert.assertNull(header);
    } 
 
    @Test 
    public void testPreserveAuthHeader() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        request.addHeader(AUTH.WWW_AUTH_RESP, "Basic c3R1ZmY6c3R1ZmY=");
        HttpContext context = new BasicHttpContext();
 
        BasicScheme authscheme = new BasicScheme();
        Credentials creds = new UsernamePasswordCredentials("user", "secret");
 
        BasicHeader challenge = new BasicHeader(AUTH.WWW_AUTH, "BASIC realm=auth-realm");
        authscheme.processChallenge(challenge);
 
        AuthState authstate = new AuthState();
        authstate.update(authscheme, creds);
 
        context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
 

5
CodeRank
This code example shows how to use the following methods:
                connReuseStrategy,
                responseFactory,
                handlerResolver);
        final HttpCoreContext context = HttpCoreContext.create();
        final HttpServerConnection conn = Mockito.mock(HttpServerConnection.class);
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 200, context)).thenReturn(response);
        Mockito.when(connReuseStrategy.keepAlive(response, context)).thenReturn(Boolean.FALSE);
 
        httpservice.handleRequest(conn, context);
 
        Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusLine().getStatusCode());
 
        Assert.assertSame(conn, context.getConnection());
        Assert.assertSame(request, context.getRequest());
        Assert.assertSame(response, context.getResponse());
 
        Mockito.verify(httprocessor).process(request, context);

5
CodeRank
This code example shows how to use the following methods:
    @Test 
    public void testLookup() throws Exception { 
        final UriPatternMatcher<HttpRequestHandler> matcher = Mockito.spy(new UriPatternMatcher<HttpRequestHandler>());
        final UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper(matcher);
 
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        registry.lookup(request);
        registry.unregister("/h1");
 
        Mockito.verify(matcher).lookup("/"); 
    } 
 
    @Test(expected=IllegalArgumentException.class) 
    public void testRegisterNull() throws Exception { 
        final UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper();
        registry.register(null, null);
    } 
 
    @Test(expected=IllegalArgumentException.class) 
    public void testLookupNull() throws Exception { 
5
CodeRank
See Code Examples for Android BasicHttpRequest Methods: