查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http;
17  
18  import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
19  
20  import java.util.Collection;
21  import java.util.List;
22  
23  /**
24   * A <a href="https://tools.ietf.org/html/rfc6265">RFC6265</a> compliant cookie encoder to be used server side,
25   * so some fields are sent (Version is typically ignored).
26   *
27   * As Netty's Cookie merges Expires and MaxAge into one single field, only Max-Age field is sent.
28   *
29   * Note that multiple cookies must be sent as separate "Set-Cookie" headers.
30   *
31   * <pre>
32   * // Example
33   * {@link HttpResponse} res = ...;
34   * res.setHeader("Set-Cookie", {@link ServerCookieEncoder}.encode("JSESSIONID", "1234"));
35   * </pre>
36   *
37   * @see ServerCookieDecoder
38   *
39   * @deprecated Use {@link io.netty.handler.codec.http.cookie.ServerCookieEncoder} instead
40   */
41  @Deprecated
42  public final class ServerCookieEncoder {
43  
44      /**
45       * Encodes the specified cookie name-value pair into a Set-Cookie header value.
46       *
47       * @param name the cookie name
48       * @param value the cookie value
49       * @return a single Set-Cookie header value
50       */
51      @Deprecated
52      public static String encode(String name, String value) {
53          return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(name, value);
54      }
55  
56      /**
57       * Encodes the specified cookie into a Set-Cookie header value.
58       *
59       * @param cookie the cookie
60       * @return a single Set-Cookie header value
61       */
62      @Deprecated
63      public static String encode(Cookie cookie) {
64          return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookie);
65      }
66  
67      /**
68       * Batch encodes cookies into Set-Cookie header values.
69       *
70       * @param cookies a bunch of cookies
71       * @return the corresponding bunch of Set-Cookie headers
72       */
73      @Deprecated
74      public static List<String> encode(Cookie... cookies) {
75          return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies);
76      }
77  
78      /**
79       * Batch encodes cookies into Set-Cookie header values.
80       *
81       * @param cookies a bunch of cookies
82       * @return the corresponding bunch of Set-Cookie headers
83       */
84      @Deprecated
85      public static List<String> encode(Collection<Cookie> cookies) {
86          return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies);
87      }
88  
89      /**
90       * Batch encodes cookies into Set-Cookie header values.
91       *
92       * @param cookies a bunch of cookies
93       * @return the corresponding bunch of Set-Cookie headers
94       */
95      @Deprecated
96      public static List<String> encode(Iterable<Cookie> cookies) {
97          return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies);
98      }
99  
100     private ServerCookieEncoder() {
101         // Unused
102     }
103 }