1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.http.cookie;
17
18 import static org.jboss.netty.handler.codec.http.cookie.CookieUtil.firstInvalidCookieNameOctet;
19 import static org.jboss.netty.handler.codec.http.cookie.CookieUtil.firstInvalidCookieValueOctet;
20 import static org.jboss.netty.handler.codec.http.cookie.CookieUtil.unwrapValue;
21
22
23
24
25 public abstract class CookieEncoder {
26
27 private final boolean strict;
28
29 protected CookieEncoder(boolean strict) {
30 this.strict = strict;
31 }
32
33 protected void validateCookie(String name, String value) {
34 if (strict) {
35 int pos;
36
37 if ((pos = firstInvalidCookieNameOctet(name)) >= 0) {
38 throw new IllegalArgumentException("Cookie name contains an invalid char: " + name.charAt(pos));
39 }
40
41 CharSequence unwrappedValue = unwrapValue(value);
42 if (unwrappedValue == null) {
43 throw new IllegalArgumentException("Cookie value wrapping quotes are not balanced: " + value);
44 }
45
46 if ((pos = firstInvalidCookieValueOctet(unwrappedValue)) >= 0) {
47 throw new IllegalArgumentException("Cookie value contains an invalid char: " + value.charAt(pos));
48 }
49 }
50 }
51 }