mobile/android/thirdparty/ch/boye/httpclientandroidlib/cookie/CookieOrigin.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/cookie/CookieOrigin.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     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 +package ch.boye.httpclientandroidlib.cookie;
    1.31 +
    1.32 +import java.util.Locale;
    1.33 +
    1.34 +import ch.boye.httpclientandroidlib.annotation.Immutable;
    1.35 +
    1.36 +/**
    1.37 + * CookieOrigin class encapsulates details of an origin server that
    1.38 + * are relevant when parsing, validating or matching HTTP cookies.
    1.39 + *
    1.40 + * @since 4.0
    1.41 + */
    1.42 +@Immutable
    1.43 +public final class CookieOrigin {
    1.44 +
    1.45 +    private final String host;
    1.46 +    private final int port;
    1.47 +    private final String path;
    1.48 +    private final boolean secure;
    1.49 +
    1.50 +    public CookieOrigin(final String host, int port, final String path, boolean secure) {
    1.51 +        super();
    1.52 +        if (host == null) {
    1.53 +            throw new IllegalArgumentException(
    1.54 +                    "Host of origin may not be null");
    1.55 +        }
    1.56 +        if (host.trim().length() == 0) {
    1.57 +            throw new IllegalArgumentException(
    1.58 +                    "Host of origin may not be blank");
    1.59 +        }
    1.60 +        if (port < 0) {
    1.61 +            throw new IllegalArgumentException("Invalid port: " + port);
    1.62 +        }
    1.63 +        if (path == null) {
    1.64 +            throw new IllegalArgumentException(
    1.65 +                    "Path of origin may not be null.");
    1.66 +        }
    1.67 +        this.host = host.toLowerCase(Locale.ENGLISH);
    1.68 +        this.port = port;
    1.69 +        if (path.trim().length() != 0) {
    1.70 +            this.path = path;
    1.71 +        } else {
    1.72 +            this.path = "/";
    1.73 +        }
    1.74 +        this.secure = secure;
    1.75 +    }
    1.76 +
    1.77 +    public String getHost() {
    1.78 +        return this.host;
    1.79 +    }
    1.80 +
    1.81 +    public String getPath() {
    1.82 +        return this.path;
    1.83 +    }
    1.84 +
    1.85 +    public int getPort() {
    1.86 +        return this.port;
    1.87 +    }
    1.88 +
    1.89 +    public boolean isSecure() {
    1.90 +        return this.secure;
    1.91 +    }
    1.92 +
    1.93 +    @Override
    1.94 +    public String toString() {
    1.95 +        StringBuilder buffer = new StringBuilder();
    1.96 +        buffer.append('[');
    1.97 +        if (this.secure) {
    1.98 +            buffer.append("(secure)");
    1.99 +        }
   1.100 +        buffer.append(this.host);
   1.101 +        buffer.append(':');
   1.102 +        buffer.append(Integer.toString(this.port));
   1.103 +        buffer.append(this.path);
   1.104 +        buffer.append(']');
   1.105 +        return buffer.toString();
   1.106 +    }
   1.107 +
   1.108 +}

mercurial