1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.tomcat.util.http;
18
19 import java.io.Serializable;
20
21 import org.apache.tomcat.util.buf.MessageBytes;
22
23
24 /**
25 * Server-side cookie representation.
26 * Allows recycling and uses MessageBytes as low-level
27 * representation ( and thus the byte -> char conversion can be delayed
28 * until we know the charset ).
29 *
30 * Tomcat.core uses this recyclable object to represent cookies,
31 * and the facade will convert it to the external representation.
32 */
33 public class ServerCookie implements Serializable {
34
35 private static final long serialVersionUID = 1L;
36
37 // Version 0 (Netscape) attributes
38 private final MessageBytes name=MessageBytes.newInstance();
39 private final MessageBytes value=MessageBytes.newInstance();
40 // Expires - Not stored explicitly. Generated from Max-Age (see V1)
41 private final MessageBytes path=MessageBytes.newInstance();
42 private final MessageBytes domain=MessageBytes.newInstance();
43
44 // Version 1 (RFC2109) attributes
45 private final MessageBytes comment=MessageBytes.newInstance();
46 private int version = 0;
47
48 // Note: Servlet Spec =< 3.0 only refers to Netscape and RFC2109, not RFC2965
49
50 // Version 2 (RFC2965) attributes that would need to be added to support v2 cookies
51 // CommentURL
52 // Discard - implied by maxAge <0
53 // Port
54
55 public ServerCookie() {
56 // NOOP
57 }
58
59 public void recycle() {
60 name.recycle();
61 value.recycle();
62 comment.recycle();
63 path.recycle();
64 domain.recycle();
65 version=0;
66 }
67
68 public MessageBytes getComment() {
69 return comment;
70 }
71
72 public MessageBytes getDomain() {
73 return domain;
74 }
75
76 public MessageBytes getPath() {
77 return path;
78 }
79
80 public MessageBytes getName() {
81 return name;
82 }
83
84 public MessageBytes getValue() {
85 return value;
86 }
87
88 public int getVersion() {
89 return version;
90 }
91
92 public void setVersion(int v) {
93 version = v;
94 }
95
96
97 // -------------------- utils --------------------
98
99 @Override
100 public String toString() {
101 return "Cookie " + getName() + "=" + getValue() + " ; "
102 + getVersion() + " " + getPath() + " " + getDomain();
103 }
104 }
105
106