Examples of HttpVersion


Examples of org.apache.http.HttpVersion

        buffer.append(s);
        ParserCursor cursor = new ParserCursor(0, s.length());
       
        LineParser parser = BasicLineParser.DEFAULT;
       
        HttpVersion version = (HttpVersion) parser.parseProtocolVersion(buffer, cursor);
        assertEquals("HTTP protocol name", "HTTP", version.getProtocol());
        assertEquals("HTTP major version number", 1, version.getMajor());
        assertEquals("HTTP minor version number", 1, version.getMinor());
        assertEquals("HTTP version number", "HTTP/1.1", version.toString());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());
       
        s = "HTTP/1.123 123";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        version = (HttpVersion) parser.parseProtocolVersion(buffer, cursor);
        assertEquals("HTTP protocol name", "HTTP", version.getProtocol());
        assertEquals("HTTP major version number", 1, version.getMajor());
        assertEquals("HTTP minor version number", 123, version.getMinor());
        assertEquals("HTTP version number", "HTTP/1.123", version.toString());
        assertEquals(' ', buffer.charAt(cursor.getPos()));
        assertEquals(s.length() - 4, cursor.getPos());
        assertFalse(cursor.atEnd());
    }
View Full Code Here

Examples of org.apache.http.HttpVersion

        try {
            minor = Integer.parseInt(s.substring(i1, i2));
        } catch (NumberFormatException e) {
            throw new ProtocolException("Invalid HTTP minor version number: " + s);
        }
        return new HttpVersion(major, minor);
    }
View Full Code Here

Examples of org.apache.http.HttpVersion

   
    public RequestLine getRequestLine() {
        if (this.requestline != null) {
            return this.requestline;
        } else {
            HttpVersion ver = HttpProtocolParams.getVersion(getParams());
            return new RequestLine(this.method, this.uri, ver);
        }
    }
View Full Code Here

Examples of org.apache.http.HttpVersion

    public boolean keepAlive(final HttpResponse response) {
        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
        HttpEntity entity = response.getEntity();
        HttpVersion ver = response.getStatusLine().getHttpVersion();
        if (entity != null) {
            if (entity.getContentLength() < 0) {
                if (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0)) {
                    // if the content length is not known and is not chunk
                    // encoded, the connection cannot be reused
                    return false;
                }
            }
        }
        // Check for 'Connection' directive
        Header connheader = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
        if (connheader != null) {
            String conndirective = connheader.getValue();
            if (HTTP.CONN_CLOSE.equalsIgnoreCase(conndirective)) {
                return false;
            } else if (HTTP.CONN_KEEP_ALIVE.equalsIgnoreCase(conndirective)) {
                return true;
            } else {
                // log unknown directive
            }
        }
        // Resorting to protocol version default close connection policy
        return ver.greaterEquals(HttpVersion.HTTP_1_1);
    }
View Full Code Here

Examples of org.apache.http.HttpVersion

            throw new ProtocolException("Transfer-encoding header already present");
        }
        if (response.containsHeader(HTTP.CONTENT_LEN)) {
            throw new ProtocolException("Content-Length header already present");
        }
        HttpVersion ver = response.getStatusLine().getHttpVersion();
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            long len = entity.getContentLength();
            if (entity.isChunked() && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
                response.addHeader(new Header(HTTP.TRANSFER_ENCODING,
                        HTTP.CHUNK_CODING));
            } else if (len >= 0) {
                response.addHeader(new Header(HTTP.CONTENT_LEN,
                        Long.toString(entity.getContentLength())));
View Full Code Here

Examples of org.apache.http.HttpVersion

            // Check for expect-continue handshake. We have to flush the
            // headers and wait for an 100-continue response to handle it.
            // If we get a different response, we must not send the entity.
            boolean sendentity = true;
            final HttpVersion ver = request.getRequestLine().getHttpVersion();
            if (entityEnclRequest.expectContinue() &&
                ver.greaterEquals(HttpVersion.HTTP_1_1)) {

                conn.flush();
                // As suggested by RFC 2616 section 8.2.3, we don't wait for a
                // 100-continue response forever. On timeout, send the entity.
                if (conn.isResponseAvailable(WAIT_FOR_CONTINUE_MS)) {
View Full Code Here

Examples of org.apache.http.HttpVersion

        }
        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
            // Do not send the expect header if request body is known to be empty
            if (entity != null && entity.getContentLength() != 0) {
                HttpVersion ver = request.getRequestLine().getHttpVersion();
                if (HttpProtocolParams.useExpectContinue(request.getParams())
                        && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
                    request.addHeader(new Header(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE));
                }
            }
        }
    }
View Full Code Here

Examples of org.apache.http.HttpVersion

                throw new ProtocolException("Transfer-encoding header already present");
            }
            if (request.containsHeader(HTTP.CONTENT_LEN)) {
                throw new ProtocolException("Content-Length header already present");
            }
            HttpVersion ver = request.getRequestLine().getHttpVersion();
            HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
            if (entity == null) {
                request.setHeader(new Header(HTTP.CONTENT_LEN, "0"));
                return;
            }
            // Must specify a transfer encoding or a content length
            if (entity.isChunked() || entity.getContentLength() < 0) {
                if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
                    throw new ProtocolException(
                            "Chunked transfer encoding not allowed for " + ver);
                }
                request.addHeader(new Header(HTTP.TRANSFER_ENCODING,
                        HTTP.CHUNK_CODING));
View Full Code Here

Examples of org.apache.http.HttpVersion

        }
    }
   
    protected void doService(final HttpRequest request, final HttpResponse response)
            throws HttpException, IOException {
        HttpVersion ver = request.getRequestLine().getHttpVersion();
        if (ver.lessEquals(HttpVersion.HTTP_1_1)) {
            response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
        } else {
            response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_IMPLEMENTED));
        }
    }
View Full Code Here

Examples of org.apache.http.HttpVersion

        assertTrue(reuseStrategy.keepAlive(response, context));
    }

    public void testFutureHTTP() throws Exception {
        HttpResponse response =
            createResponse(new HttpVersion(3, 45), 200, "OK");

        assertTrue(reuseStrategy.keepAlive(response, context));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.