Package org.apache.http

Examples of org.apache.http.HeaderIterator


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

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
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);

        assertFalse(ti.hasNext());

View Full Code Here

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

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
View Full Code Here

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

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
View Full Code Here

    public void testTokenChar() {
        Header[] headers = new Header[]{
            new BasicHeader("Name", "token0")
        };
        HeaderIterator     hit = new BasicHeaderIterator(headers, null);
        BasicTokenIterator bti = new BasicTokenIterator(hit);

        assertTrue ("letter"   , bti.isTokenChar('j'));
        assertFalse("control"  , bti.isTokenChar('\b'));
        assertFalse("separator", bti.isTokenChar('?'));
View Full Code Here

            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

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.