Package org.apache.http

Examples of org.apache.http.HttpVersion


            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 (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) {
            // 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 = request.getParams().getIntParameter(
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

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

        try {

            HttpRequest request = conn.receiveRequestHeader();
            HttpParamsLinker.link(request, this.params);
           
            HttpVersion ver = request.getRequestLine().getHttpVersion();
            if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
                // Downgrade protocol version if greater than HTTP/1.1
                ver = HttpVersion.HTTP_1_1;
            }

            if (request instanceof HttpEntityEnclosingRequest) {
View Full Code Here

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

                minor = Integer.parseInt(buffer.substringTrimmed(period + 1, indexTo));
            } catch (NumberFormatException e) {
                throw new ProtocolException("Invalid HTTP minor version number: " +
                        buffer.substring(indexFrom, indexTo));
            }
            return new HttpVersion(major, minor);
           
        } catch (IndexOutOfBoundsException e) {
            throw new ProtocolException("Invalid HTTP version string: " +
                    buffer.substring(indexFrom, indexTo));
        }
View Full Code Here

    }

    // non-javadoc, see interface HttpResponse
    public void setStatusCode(int code) {
        // argument checked in BasicStatusLine constructor
        HttpVersion ver = this.statusline.getHttpVersion();
        this.statusline = new BasicStatusLine(ver, code, getReason(code));
    }
View Full Code Here

        if (conn != null && !conn.isOpen())
            return false;
        // do NOT check for stale connection, that is an expensive operation

        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) {
            connheader = response.getFirstHeader("Proxy-Connection");
        }
        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

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.