Package org.apache.http.nio.impl.codecs

Examples of org.apache.http.nio.impl.codecs.HttpRequestParser


            final HttpParams params) {
        super(session, params);
        if (requestFactory == null) {
            throw new IllegalArgumentException("Request factory may not be null");
        }
        this.requestParser = new HttpRequestParser(this.inbuf, requestFactory);
    }
View Full Code Here


    }

    public void testSimpleParsing() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);
        requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.1\r\nSome header: stuff\r\n\r\n"));
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNotNull(request);
        assertEquals("/whatever", request.getRequestLine().getUri());
        assertEquals(1, request.getAllHeaders().length);
    }
View Full Code Here

    }

    public void testParsingChunkedMessages() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);

        requestParser.fillBuffer(newChannel("GET /whatev"));
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("er HTTP/1.1\r"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\nSome header: stuff\r\n\r\n"));
        request = (HttpRequest) requestParser.parse();

        assertNotNull(request);
        assertEquals("/whatever", request.getRequestLine().getUri());
        assertEquals(1, request.getAllHeaders().length);
       
View Full Code Here

    }

    public void testParsingFoldedHeaders() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);

        requestParser.fillBuffer(newChannel("GET /whatev"));
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("er HTTP/1.1\r"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\nSome header: stuff\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("   more\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\tstuff\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\r\n"));
        request = (HttpRequest) requestParser.parse();

        assertNotNull(request);
        assertEquals("/whatever", request.getRequestLine().getUri());
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("stuff more stuff", request.getFirstHeader("Some header").getValue());
View Full Code Here

    }
   
    public void testParsingBadlyFoldedFirstHeader() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);

        requestParser.fillBuffer(newChannel("GET /whatev"));
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("er HTTP/1.1\r"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\n  Some header: stuff\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("   more stuff\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\r\n"));
        request = (HttpRequest) requestParser.parse();

        assertNotNull(request);
        assertEquals("/whatever", request.getRequestLine().getUri());
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("stuff more stuff", request.getFirstHeader("Some header").getValue());
View Full Code Here

    }
   
    public void testParsingEmptyFoldedHeader() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);

        requestParser.fillBuffer(newChannel("GET /whatev"));
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("er HTTP/1.1\r"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\n  Some header: stuff\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("      \r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("      more stuff\r\n"));
        request = (HttpRequest) requestParser.parse();
        assertNull(request);
        requestParser.fillBuffer(newChannel("\r\n"));
        request = (HttpRequest) requestParser.parse();

        assertNotNull(request);
        assertEquals("/whatever", request.getRequestLine().getUri());
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("stuff  more stuff", request.getFirstHeader("Some header").getValue());
View Full Code Here

    }
   
    public void testParsingIncompleteRequestLine() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);
       
        ReadableByteChannel channel = newChannel("GET /whatever HTTP/1.0");
        requestParser.fillBuffer(channel);
        requestParser.fillBuffer(channel);
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNotNull(request);
        assertEquals(HttpVersion.HTTP_1_0, request.getRequestLine().getHttpVersion());
    }
View Full Code Here

    }
   
    public void testParsingIncompleteHeader() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);
       
        ReadableByteChannel channel = newChannel("GET /whatever HTTP/1.0\r\nHeader: whatever");
        requestParser.fillBuffer(channel);
        requestParser.fillBuffer(channel);
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNotNull(request);
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("whatever", request.getFirstHeader("Header").getValue());
    }
View Full Code Here

    }
   
    public void testParsingInvalidRequestLine() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);
       
        ReadableByteChannel channel = newChannel("GET garbage\r\n");
        requestParser.fillBuffer(channel);
        try {
            requestParser.parse();
            fail("HttpException should have been thrown");
        } catch (HttpException ex) {
            // expected
        }
    }
View Full Code Here

    }
   
    public void testResetParser() throws Exception {
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 128);
        HttpRequestFactory requestFactory = new DefaultHttpRequestFactory();
        HttpRequestParser requestParser = new HttpRequestParser(inbuf, requestFactory);
       
        ReadableByteChannel channel = newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n\r\n");
        requestParser.fillBuffer(channel);
        HttpRequest request = (HttpRequest) requestParser.parse();
        assertNotNull(request);
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("one", request.getFirstHeader("Header").getValue());
       
        requestParser.reset();

        channel = newChannel("GET /whatever HTTP/1.0\r\nHeader: two\r\n\r\n");
        requestParser.fillBuffer(channel);
        request = (HttpRequest) requestParser.parse();
        assertNotNull(request);
        assertEquals(1, request.getAllHeaders().length);
        assertEquals("two", request.getFirstHeader("Header").getValue());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.impl.codecs.HttpRequestParser

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.