Package org.apache.http

Examples of org.apache.http.HeaderIterator


            new BasicHeader("in", "token0=token1"),
            new BasicHeader("no", "token0 token1"),
            new BasicHeader("pre", "<token0,token1"),
            new BasicHeader("post", "token0,token1="),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, "in");
        TokenIterator  ti  = new BasicTokenIterator(hit);

        // constructor located token0
        assertTrue(ti.hasNext());
        try {
View Full Code Here


            new BasicHeader("Name", " "),
            new BasicHeader("Name", ""),
            new BasicHeader("Name", ","),
            new BasicHeader("Name", " ,, "),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        try {
            // call next() instead of nextToken() to get that covered, too
            ti.next();
View Full Code Here

    public void testWrongProtected() {

        Header[] headers = new Header[]{
            new BasicHeader("Name", "token1,token2")
        };
        HeaderIterator     hit = new BasicHeaderIterator(headers, null);
        BasicTokenIterator bti = new BasicTokenIterator(hit);

        try {
            bti.findTokenStart(-1);
            fail("tokenStart: negative index not detected");
View Full Code Here

        }

        // Check for the "Connection" header. If that is absent, check for
        // the "Proxy-Connection" header. The latter is an unspecified and
        // broken but unfortunately common extension of HTTP.
        HeaderIterator hit = response.headerIterator(HTTP.CONN_DIRECTIVE);
        if (!hit.hasNext())
            hit = response.headerIterator("Proxy-Connection");

        // Experimental usage of the "Connection" header in HTTP/1.0 is
        // documented in RFC 2068, section 19.7.1. A token "keep-alive" is
        // used to indicate that the connection should be persistent.
        // Note that the final specification of HTTP/1.1 in RFC 2616 does not
        // include this information. Neither is the "Connection" header
        // mentioned in RFC 1945, which informally describes HTTP/1.0.
        //
        // RFC 2616 specifies "close" as the only connection token with a
        // specific meaning: it disables persistent connections.
        //
        // The "Proxy-Connection" header is not formally specified anywhere,
        // but is commonly used to carry one token, "close" or "keep-alive".
        // The "Connection" header, on the other hand, is defined as a
        // sequence of tokens, where each token is a header name, and the
        // token "close" has the above-mentioned additional meaning.
        //
        // To get through this mess, we treat the "Proxy-Connection" header
        // in exactly the same way as the "Connection" header, but only if
        // the latter is missing. We scan the sequence of tokens for both
        // "close" and "keep-alive". As "close" is specified by RFC 2068,
        // it takes precedence and indicates a non-persistent connection.
        // If there is no "close" but a "keep-alive", we take the hint.

        if (hit.hasNext()) {
            try {
                TokenIterator ti = createTokenIterator(hit);
                boolean keepalive = false;
                while (ti.hasNext()) {
                    final String token = ti.nextToken();
View Full Code Here

            new BasicHeader("naMe", "value2=whatever"),
            new BasicHeader("namE", "value3;tag=nil"),
        };

        // without filter
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter
        hit = new BasicHeaderIterator(headers, "name");
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertFalse(hit.hasNext());
    }
View Full Code Here

            new BasicHeader("single"  , "value2=whatever"),
            new BasicHeader("match"   , "value3;tag=nil"),
        };

        // without filter
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter, first & last
        hit = new BasicHeaderIterator(headers, "match");
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter, one match
        hit = new BasicHeaderIterator(headers, "single");
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertFalse(hit.hasNext());

        // with filter, no match
        hit = new BasicHeaderIterator(headers, "way-off");
        assertFalse(hit.hasNext());
    }
View Full Code Here

            new BasicHeader("yellow", "0d"),
            new BasicHeader("orange", "0e"),
        };

        // without filter
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("4", headers[4], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("5", headers[5], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("6", headers[6], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("7", headers[7], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("8", headers[8], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("9", headers[9], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("a", headers[10], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("b", headers[11], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("c", headers[12], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("d", headers[13], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("e", headers[14], hit.nextHeader());
        assertFalse(hit.hasNext());

        // yellow 0, 5, 9, 11, 13
        hit = new BasicHeaderIterator(headers, "Yellow");
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("5", headers[5], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("9", headers[9], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("b", headers[11], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("d", headers[13], hit.nextHeader());
        assertFalse(hit.hasNext());

        // maroon 1, 6, 7, 8, 10
        hit = new BasicHeaderIterator(headers, "marOOn");
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("6", headers[6], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("7", headers[7], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("8", headers[8], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("a", headers[10], hit.nextHeader());
        assertFalse(hit.hasNext());

        // orange 2, 3, 4, 12, 14
        hit = new BasicHeaderIterator(headers, "OranGe");
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("4", headers[4], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("b", headers[12], hit.nextHeader());
        assertTrue(hit.hasNext());
        assertEquals("e", headers[14], hit.nextHeader());
        assertFalse(hit.hasNext());
    }
View Full Code Here

    }


    public void testInvalid() {

        HeaderIterator hit = null;
        try {
            hit = new BasicHeaderIterator(null, "whatever");
            fail("null headers not detected");
        } catch (IllegalArgumentException iax) {
            // expected
        }

        // this is not invalid
        hit = new BasicHeaderIterator(new Header[0], "whatever");
        assertFalse(hit.hasNext());

        // but this is
        try {
            hit.nextHeader();
            fail("next beyond end not detected");
        } catch (NoSuchElementException nsx) {
            // expected
        }
    }
View Full Code Here

            new BasicHeader("naMe", "value2=whatever"),
            new BasicHeader("namE", "value3;tag=nil"),
        };

        // without filter, using plain next()
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        assertEquals("0", headers[0], hit.next());
        assertTrue(hit.hasNext());
        assertEquals("1", headers[1], hit.next());
        assertTrue(hit.hasNext());
        assertEquals("2", headers[2], hit.next());
        assertTrue(hit.hasNext());
        assertEquals("3", headers[3], hit.next());
        assertFalse(hit.hasNext());

        hit = new BasicHeaderIterator(headers, null);
        assertTrue(hit.hasNext());
        try {
            hit.remove();
            fail("remove not detected");
        } catch (UnsupportedOperationException uox) {
            // expected
        }
View Full Code Here

    public Set<String> getAllowedMethods(final HttpResponse response) {
        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
       
        HeaderIterator it = response.headerIterator("Allow");
        Set<String> methods = new HashSet<String>();
        while (it.hasNext()) {
            Header header = it.nextHeader();
            HeaderElement[] elements = header.getElements();
            for (HeaderElement element : elements) {
                methods.add(element.getName());
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.http.HeaderIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.