michael@0: /*
michael@0: * ====================================================================
michael@0: * Licensed to the Apache Software Foundation (ASF) under one
michael@0: * or more contributor license agreements. See the NOTICE file
michael@0: * distributed with this work for additional information
michael@0: * regarding copyright ownership. The ASF licenses this file
michael@0: * to you under the Apache License, Version 2.0 (the
michael@0: * "License"); you may not use this file except in compliance
michael@0: * with the License. You may obtain a copy of the License at
michael@0: *
michael@0: * http://www.apache.org/licenses/LICENSE-2.0
michael@0: *
michael@0: * Unless required by applicable law or agreed to in writing,
michael@0: * software distributed under the License is distributed on an
michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0: * KIND, either express or implied. See the License for the
michael@0: * specific language governing permissions and limitations
michael@0: * under the License.
michael@0: * ====================================================================
michael@0: *
michael@0: * This software consists of voluntary contributions made by many
michael@0: * individuals on behalf of the Apache Software Foundation. For more
michael@0: * information on the Apache Software Foundation, please see
michael@0: * .
michael@0: *
michael@0: */
michael@0:
michael@0: package ch.boye.httpclientandroidlib.cookie;
michael@0:
michael@0: import java.util.List;
michael@0:
michael@0: import ch.boye.httpclientandroidlib.Header;
michael@0:
michael@0: /**
michael@0: * Defines the cookie management specification.
michael@0: *
Cookie management specification must define
michael@0: *
michael@0: * - rules of parsing "Set-Cookie" header
michael@0: *
- rules of validation of parsed cookies
michael@0: *
- formatting of "Cookie" header
michael@0: *
michael@0: * for a given host, port and path of origin
michael@0: *
michael@0: *
michael@0: * @since 4.0
michael@0: */
michael@0: public interface CookieSpec {
michael@0:
michael@0: /**
michael@0: * Returns version of the state management this cookie specification
michael@0: * conforms to.
michael@0: *
michael@0: * @return version of the state management specification
michael@0: */
michael@0: int getVersion();
michael@0:
michael@0: /**
michael@0: * Parse the "Set-Cookie" Header into an array of Cookies.
michael@0: *
michael@0: * This method will not perform the validation of the resultant
michael@0: * {@link Cookie}s
michael@0: *
michael@0: * @see #validate
michael@0: *
michael@0: * @param header the Set-Cookie received from the server
michael@0: * @param origin details of the cookie origin
michael@0: * @return an array of Cookies parsed from the header
michael@0: * @throws MalformedCookieException if an exception occurs during parsing
michael@0: */
michael@0: List parse(Header header, CookieOrigin origin) throws MalformedCookieException;
michael@0:
michael@0: /**
michael@0: * Validate the cookie according to validation rules defined by the
michael@0: * cookie specification.
michael@0: *
michael@0: * @param cookie the Cookie to validate
michael@0: * @param origin details of the cookie origin
michael@0: * @throws MalformedCookieException if the cookie is invalid
michael@0: */
michael@0: void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException;
michael@0:
michael@0: /**
michael@0: * Determines if a Cookie matches the target location.
michael@0: *
michael@0: * @param cookie the Cookie to be matched
michael@0: * @param origin the target to test against
michael@0: *
michael@0: * @return true if the cookie should be submitted with a request
michael@0: * with given attributes, false otherwise.
michael@0: */
michael@0: boolean match(Cookie cookie, CookieOrigin origin);
michael@0:
michael@0: /**
michael@0: * Create "Cookie" headers for an array of Cookies.
michael@0: *
michael@0: * @param cookies the Cookies format into a Cookie header
michael@0: * @return a Header for the given Cookies.
michael@0: * @throws IllegalArgumentException if an input parameter is illegal
michael@0: */
michael@0: List formatCookies(List cookies);
michael@0:
michael@0: /**
michael@0: * Returns a request header identifying what version of the state management
michael@0: * specification is understood. May be null
if the cookie
michael@0: * specification does not support Cookie2 header.
michael@0: */
michael@0: Header getVersionHeader();
michael@0:
michael@0: }