View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.client5.http.cookie;
29  
30  import java.time.Instant;
31  import java.util.Date;
32  
33  import org.apache.hc.client5.http.utils.DateUtils;
34  
35  /**
36   * This interface represents a {@code Set-Cookie} response header sent by the
37   * origin server to the HTTP agent in order to maintain a conversational state.
38   *
39   * @since 4.0
40   */
41  public interface SetCookie extends Cookie {
42  
43      void setValue(String value);
44  
45      /**
46       * Sets expiration date.
47       * <p><strong>Note:</strong> the object returned by this method is considered
48       * immutable. Changing it (e.g. using setTime()) could result in undefined
49       * behaviour. Do so at your peril.</p>
50       *
51       * @param expiryDate the {@link Date} after which this cookie is no longer valid.
52       *
53       * @see Cookie#getExpiryDate
54       * @deprecated Use {{@link #setExpiryDate(Instant)}}
55       */
56      @Deprecated
57      void setExpiryDate (Date expiryDate);
58  
59      /**
60       * Sets expiration date.
61       * <p><strong>Note:</strong> the object returned by this method is considered
62       * immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at
63       * your peril.</p>
64       *
65       * @param expiryDate the {@link Instant} after which this cookie is no longer valid.
66       * @see Cookie#getExpiryInstant()
67       * @since 5.2
68       */
69      @SuppressWarnings("deprecated")
70      default void setExpiryDate(Instant expiryDate) {
71          setExpiryDate(DateUtils.toDate(expiryDate));
72      }
73  
74      /**
75       * Sets the domain attribute.
76       *
77       * @param domain The value of the domain attribute
78       *
79       * @see Cookie#getDomain
80       */
81      void setDomain(String domain);
82  
83      /**
84       * Sets the path attribute.
85       *
86       * @param path The value of the path attribute
87       *
88       * @see Cookie#getPath
89       *
90       */
91      void setPath(String path);
92  
93      /**
94       * Sets the secure attribute of the cookie.
95       * <p>
96       * When {@code true} the cookie should only be sent
97       * using a secure protocol (https).  This should only be set when
98       * the cookie's originating server used a secure protocol to set the
99       * cookie's value.
100      *
101      * @param secure The value of the secure attribute
102      *
103      * @see #isSecure()
104      */
105     void setSecure (boolean secure);
106 
107     /**
108      * Marks or unmarks  this Cookie as {@code httpOnly}.
109      *
110      * @param httpOnly true if this cookie is to be marked as
111      * {@code httpOnly}, false otherwise
112      *
113      * @since 5.2
114      */
115     default void setHttpOnly (final boolean httpOnly){
116     }
117 
118 }
119