mobile/android/thirdparty/ch/boye/httpclientandroidlib/message/BasicHttpRequest.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/message/BasicHttpRequest.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     1.4 +/*
     1.5 + * ====================================================================
     1.6 + * Licensed to the Apache Software Foundation (ASF) under one
     1.7 + * or more contributor license agreements.  See the NOTICE file
     1.8 + * distributed with this work for additional information
     1.9 + * regarding copyright ownership.  The ASF licenses this file
    1.10 + * to you under the Apache License, Version 2.0 (the
    1.11 + * "License"); you may not use this file except in compliance
    1.12 + * with the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *   http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing,
    1.17 + * software distributed under the License is distributed on an
    1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    1.19 + * KIND, either express or implied.  See the License for the
    1.20 + * specific language governing permissions and limitations
    1.21 + * under the License.
    1.22 + * ====================================================================
    1.23 + *
    1.24 + * This software consists of voluntary contributions made by many
    1.25 + * individuals on behalf of the Apache Software Foundation.  For more
    1.26 + * information on the Apache Software Foundation, please see
    1.27 + * <http://www.apache.org/>.
    1.28 + *
    1.29 + */
    1.30 +
    1.31 +package ch.boye.httpclientandroidlib.message;
    1.32 +
    1.33 +import ch.boye.httpclientandroidlib.HttpRequest;
    1.34 +import ch.boye.httpclientandroidlib.ProtocolVersion;
    1.35 +import ch.boye.httpclientandroidlib.RequestLine;
    1.36 +import ch.boye.httpclientandroidlib.params.HttpParams;
    1.37 +import ch.boye.httpclientandroidlib.params.HttpProtocolParams;
    1.38 +
    1.39 +/**
    1.40 + * Basic implementation of {@link HttpRequest}.
    1.41 + * <p>
    1.42 + * The following parameters can be used to customize the behavior of this class:
    1.43 + * <ul>
    1.44 + *  <li>{@link ch.boye.httpclientandroidlib.params.CoreProtocolPNames#PROTOCOL_VERSION}</li>
    1.45 + * </ul>
    1.46 + *
    1.47 + * @since 4.0
    1.48 + */
    1.49 +public class BasicHttpRequest extends AbstractHttpMessage implements HttpRequest {
    1.50 +
    1.51 +    private final String method;
    1.52 +    private final String uri;
    1.53 +
    1.54 +    private RequestLine requestline;
    1.55 +
    1.56 +    /**
    1.57 +     * Creates an instance of this class using the given request method
    1.58 +     * and URI. The HTTP protocol version will be obtained from the
    1.59 +     * {@link HttpParams} instance associated with the object.
    1.60 +     * The initialization will be deferred
    1.61 +     * until {@link #getRequestLine()} is accessed for the first time.
    1.62 +     *
    1.63 +     * @param method request method.
    1.64 +     * @param uri request URI.
    1.65 +     */
    1.66 +    public BasicHttpRequest(final String method, final String uri) {
    1.67 +        super();
    1.68 +        if (method == null) {
    1.69 +            throw new IllegalArgumentException("Method name may not be null");
    1.70 +        }
    1.71 +        if (uri == null) {
    1.72 +            throw new IllegalArgumentException("Request URI may not be null");
    1.73 +        }
    1.74 +        this.method = method;
    1.75 +        this.uri = uri;
    1.76 +        this.requestline = null;
    1.77 +    }
    1.78 +
    1.79 +    /**
    1.80 +     * Creates an instance of this class using the given request method, URI
    1.81 +     * and the HTTP protocol version.
    1.82 +     *
    1.83 +     * @param method request method.
    1.84 +     * @param uri request URI.
    1.85 +     * @param ver HTTP protocol version.
    1.86 +     */
    1.87 +    public BasicHttpRequest(final String method, final String uri, final ProtocolVersion ver) {
    1.88 +        this(new BasicRequestLine(method, uri, ver));
    1.89 +    }
    1.90 +
    1.91 +    /**
    1.92 +     * Creates an instance of this class using the given request line.
    1.93 +     *
    1.94 +     * @param requestline request line.
    1.95 +     */
    1.96 +    public BasicHttpRequest(final RequestLine requestline) {
    1.97 +        super();
    1.98 +        if (requestline == null) {
    1.99 +            throw new IllegalArgumentException("Request line may not be null");
   1.100 +        }
   1.101 +        this.requestline = requestline;
   1.102 +        this.method = requestline.getMethod();
   1.103 +        this.uri = requestline.getUri();
   1.104 +    }
   1.105 +
   1.106 +    /**
   1.107 +     * Returns the HTTP protocol version to be used for this request. If an
   1.108 +     * HTTP protocol version was not explicitly set at the construction time,
   1.109 +     * this method will obtain it from the {@link HttpParams} instance
   1.110 +     * associated with the object.
   1.111 +     *
   1.112 +     * @see #BasicHttpRequest(String, String)
   1.113 +     */
   1.114 +    public ProtocolVersion getProtocolVersion() {
   1.115 +        return getRequestLine().getProtocolVersion();
   1.116 +    }
   1.117 +
   1.118 +    /**
   1.119 +     * Returns the request line of this request. If an HTTP protocol version
   1.120 +     * was not explicitly set at the construction time, this method will obtain
   1.121 +     * it from the {@link HttpParams} instance associated with the object.
   1.122 +     *
   1.123 +     * @see #BasicHttpRequest(String, String)
   1.124 +     */
   1.125 +    public RequestLine getRequestLine() {
   1.126 +        if (this.requestline == null) {
   1.127 +            ProtocolVersion ver = HttpProtocolParams.getVersion(getParams());
   1.128 +            this.requestline = new BasicRequestLine(this.method, this.uri, ver);
   1.129 +        }
   1.130 +        return this.requestline;
   1.131 +    }
   1.132 +
   1.133 +    public String toString() {
   1.134 +        return this.method + " " + this.uri + " " + this.headergroup;
   1.135 +    }
   1.136 +
   1.137 +}

mercurial