Package org.apache.http

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


        }
        // Always drop connection for HTTP/1.0 responses and below
        // if the content body cannot be correctly delimited
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            HttpVersion ver = response.getStatusLine().getHttpVersion();
            if (entity.getContentLength() < 0 &&
                    (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) {
                response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
                return;
            }
        }
        // Drop connection if requested by the client
View Full Code Here

            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(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
            } else if (len >= 0) {
                response.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
            }
            // Specify a content type if known
View Full Code Here

        }
        if (!request.containsHeader(HTTP.TARGET_HOST)) {
            HttpHost targethost = (HttpHost) context
                .getAttribute(HttpExecutionContext.HTTP_TARGET_HOST);
            if (targethost == null) {
                HttpVersion ver = request.getRequestLine().getHttpVersion();
                if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
                    return;
                } else {
                    throw new ProtocolException("Target host missing");
                }
            }
View Full Code Here

            if (blank <= 0) {
                throw new ProtocolException(
                        "Unable to parse HTTP-Version from the status line: "
                        + buffer.substring(indexFrom, indexTo));
            }
            HttpVersion ver = BasicHttpVersionFormat.parse(buffer, i, blank);

            i = blank;
            //advance through spaces
            while (HTTP.isWhitespace(buffer.charAt(i))) {
                i++;
View Full Code Here

        if (request instanceof HttpEntityEnclosingRequest) {
            // 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 (((HttpEntityEnclosingRequest) request).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.
                int tms = params.getIntParameter(HttpProtocolParams.WAIT_FOR_CONTINUE, 2000);
View Full Code Here

            if (blank < 0) {
                throw new ProtocolException("Invalid request line: " +
                        buffer.substring(indexFrom, indexTo));
            }
            String uri = buffer.substringTrimmed(i, blank);
            HttpVersion ver = BasicHttpVersionFormat.parse(buffer, blank, indexTo);
            return new BasicRequestLine(method, uri, ver);
        } catch (IndexOutOfBoundsException e) {
            throw new ProtocolException("Invalid request line: " +
                    buffer.substring(indexFrom, indexTo));
        }
View Full Code Here

        }
        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(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
                }
            }
        }
    }
View Full Code Here

        }
        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 GeneratedHeader(HTTP.EXPECT_DIRECTIVE,
                            HTTP.EXPECT_CONTINUE));
                }
            }
        }
View Full Code Here

                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 GeneratedHeader(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 GeneratedHeader(HTTP.TRANSFER_ENCODING,
                        HTTP.CHUNK_CODING));
View Full Code Here

TOP

Related Classes of org.apache.http.HttpVersion

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.