From 245cccd5e0ba40c803c78862d9e70ed6203e6218 Mon Sep 17 00:00:00 2001 From: Dmitriy Dumanskiy Date: Thu, 31 Jan 2019 21:35:56 +0200 Subject: [PATCH] Old cookies classes removed (#8812) Motivation: We currently include two different cookie implementations, one is deprecated and one is not. We should remove the deprecated implentation. Modifications: Remove deprecated cookies classes. Result: Less code to maintain. --- .../codec/http/ClientCookieEncoder.java | 88 ----- .../io/netty/handler/codec/http/Cookie.java | 221 ----------- .../handler/codec/http/CookieDecoder.java | 369 ------------------ .../netty/handler/codec/http/CookieUtil.java | 104 ----- .../handler/codec/http/DefaultCookie.java | 195 --------- .../codec/http/ServerCookieEncoder.java | 103 ----- .../codec/http/cookie/DefaultCookie.java | 13 - 7 files changed, 1093 deletions(-) delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/http/ClientCookieEncoder.java delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/http/Cookie.java delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/http/CookieUtil.java delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/http/ServerCookieEncoder.java diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/ClientCookieEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/ClientCookieEncoder.java deleted file mode 100644 index 51122585d4..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/ClientCookieEncoder.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.http; - -import io.netty.handler.codec.http.cookie.ClientCookieDecoder; - -/** - * A RFC6265 compliant cookie encoder to be used client side, - * so only name=value pairs are sent. - * - * User-Agents are not supposed to interpret cookies, so, if present, {@link Cookie#rawValue()} will be used. - * Otherwise, {@link Cookie#value()} will be used unquoted. - * - * Note that multiple cookies are supposed to be sent at once in a single "Cookie" header. - * - *
- * // Example
- * {@link HttpRequest} req = ...;
- * res.setHeader("Cookie", {@link ClientCookieEncoder}.encode("JSESSIONID", "1234"));
- * 
- * - * @see ClientCookieDecoder - */ -@Deprecated -public final class ClientCookieEncoder { - - /** - * Encodes the specified cookie into a Cookie header value. - * - * @param name the cookie name - * @param value the cookie value - * @return a Rfc6265 style Cookie header value - */ - @Deprecated - public static String encode(String name, String value) { - return io.netty.handler.codec.http.cookie.ClientCookieEncoder.LAX.encode(name, value); - } - - /** - * Encodes the specified cookie into a Cookie header value. - * - * @param cookie the specified cookie - * @return a Rfc6265 style Cookie header value - */ - @Deprecated - public static String encode(Cookie cookie) { - return io.netty.handler.codec.http.cookie.ClientCookieEncoder.LAX.encode(cookie); - } - - /** - * Encodes the specified cookies into a single Cookie header value. - * - * @param cookies some cookies - * @return a Rfc6265 style Cookie header value, null if no cookies are passed. - */ - @Deprecated - public static String encode(Cookie... cookies) { - return io.netty.handler.codec.http.cookie.ClientCookieEncoder.LAX.encode(cookies); - } - - /** - * Encodes the specified cookies into a single Cookie header value. - * - * @param cookies some cookies - * @return a Rfc6265 style Cookie header value, null if no cookies are passed. - */ - @Deprecated - public static String encode(Iterable cookies) { - return io.netty.handler.codec.http.cookie.ClientCookieEncoder.LAX.encode(cookies); - } - - private ClientCookieEncoder() { - // unused - } -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/Cookie.java b/codec-http/src/main/java/io/netty/handler/codec/http/Cookie.java deleted file mode 100644 index 4a362b8140..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/Cookie.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.http; - -import java.util.Set; - -/** - * An interface defining an - * HTTP cookie. - * @deprecated Use {@link io.netty.handler.codec.http.cookie.Cookie} instead. - */ -@Deprecated -public interface Cookie extends io.netty.handler.codec.http.cookie.Cookie { - - /** - * @deprecated Use {@link #name()} instead. - */ - @Deprecated - String getName(); - - /** - * @deprecated Use {@link #value()} instead. - */ - @Deprecated - String getValue(); - - /** - * @deprecated Use {@link #domain()} instead. - */ - @Deprecated - String getDomain(); - - /** - * @deprecated Use {@link #path()} instead. - */ - @Deprecated - String getPath(); - - /** - * @deprecated Use {@link #comment()} instead. - */ - @Deprecated - String getComment(); - - /** - * Returns the comment of this {@link Cookie}. - * - * @return The comment of this {@link Cookie} - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - String comment(); - - /** - * Sets the comment of this {@link Cookie}. - * - * @param comment The comment to use - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - void setComment(String comment); - - /** - * @deprecated Use {@link #maxAge()} instead. - */ - @Deprecated - long getMaxAge(); - - /** - * Returns the maximum age of this {@link Cookie} in seconds or {@link Long#MIN_VALUE} if unspecified - * - * @return The maximum age of this {@link Cookie} - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - @Override - long maxAge(); - - /** - * Sets the maximum age of this {@link Cookie} in seconds. - * If an age of {@code 0} is specified, this {@link Cookie} will be - * automatically removed by browser because it will expire immediately. - * If {@link Long#MIN_VALUE} is specified, this {@link Cookie} will be removed when the - * browser is closed. - * - * @param maxAge The maximum age of this {@link Cookie} in seconds - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - @Override - void setMaxAge(long maxAge); - - /** - * @deprecated Use {@link #version()} instead. - */ - @Deprecated - int getVersion(); - - /** - * Returns the version of this {@link Cookie}. - * - * @return The version of this {@link Cookie} - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - int version(); - - /** - * Sets the version of this {@link Cookie}. - * - * @param version The new version to use - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - void setVersion(int version); - - /** - * @deprecated Use {@link #commentUrl()} instead. - */ - @Deprecated - String getCommentUrl(); - - /** - * Returns the comment URL of this {@link Cookie}. - * - * @return The comment URL of this {@link Cookie} - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - String commentUrl(); - - /** - * Sets the comment URL of this {@link Cookie}. - * - * @param commentUrl The comment URL to use - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - void setCommentUrl(String commentUrl); - - /** - * Checks to see if this {@link Cookie} is to be discarded by the browser - * at the end of the current session. - * - * @return True if this {@link Cookie} is to be discarded, otherwise false - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - boolean isDiscard(); - - /** - * Sets the discard flag of this {@link Cookie}. - * If set to true, this {@link Cookie} will be discarded by the browser - * at the end of the current session - * - * @param discard True if the {@link Cookie} is to be discarded - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - void setDiscard(boolean discard); - - /** - * @deprecated Use {@link #ports()} instead. - */ - @Deprecated - Set getPorts(); - - /** - * Returns the ports that this {@link Cookie} can be accessed on. - * - * @return The {@link Set} of ports that this {@link Cookie} can use - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - Set ports(); - - /** - * Sets the ports that this {@link Cookie} can be accessed on. - * - * @param ports The ports that this {@link Cookie} can be accessed on - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - void setPorts(int... ports); - - /** - * Sets the ports that this {@link Cookie} can be accessed on. - * - * @param ports The {@link Iterable} collection of ports that this - * {@link Cookie} can be accessed on. - * - * @deprecated Not part of RFC6265 - */ - @Deprecated - void setPorts(Iterable ports); -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java deleted file mode 100644 index f4cf3926e1..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.http; - -import static io.netty.handler.codec.http.CookieUtil.firstInvalidCookieNameOctet; -import static io.netty.handler.codec.http.CookieUtil.firstInvalidCookieValueOctet; -import static io.netty.handler.codec.http.CookieUtil.unwrapValue; - -import io.netty.handler.codec.DateFormatter; -import io.netty.handler.codec.http.cookie.CookieHeaderNames; -import io.netty.util.internal.logging.InternalLogger; -import io.netty.util.internal.logging.InternalLoggerFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -/** - * @deprecated Use {@link io.netty.handler.codec.http.cookie.ClientCookieDecoder} - * or {@link io.netty.handler.codec.http.cookie.ServerCookieDecoder} instead. - * - * Decodes an HTTP header value into {@link Cookie}s. This decoder can decode - * the HTTP cookie version 0, 1, and 2. - * - *
- * {@link HttpRequest} req = ...;
- * String value = req.getHeader("Cookie");
- * Set<{@link Cookie}> cookies = {@link CookieDecoder}.decode(value);
- * 
- * - * @see io.netty.handler.codec.http.cookie.ClientCookieDecoder - * @see io.netty.handler.codec.http.cookie.ServerCookieDecoder - */ -@Deprecated -public final class CookieDecoder { - - private final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); - - private static final CookieDecoder STRICT = new CookieDecoder(true); - - private static final CookieDecoder LAX = new CookieDecoder(false); - - private static final String COMMENT = "Comment"; - - private static final String COMMENTURL = "CommentURL"; - - private static final String DISCARD = "Discard"; - - private static final String PORT = "Port"; - - private static final String VERSION = "Version"; - - private final boolean strict; - - public static Set decode(String header) { - return decode(header, true); - } - - public static Set decode(String header, boolean strict) { - return (strict ? STRICT : LAX).doDecode(header); - } - - /** - * Decodes the specified HTTP header value into {@link Cookie}s. - * - * @return the decoded {@link Cookie}s - */ - private Set doDecode(String header) { - List names = new ArrayList<>(8); - List values = new ArrayList<>(8); - extractKeyValuePairs(header, names, values); - - if (names.isEmpty()) { - return Collections.emptySet(); - } - - int i; - int version = 0; - - // $Version is the only attribute that can appear before the actual - // cookie name-value pair. - if (names.get(0).equalsIgnoreCase(VERSION)) { - try { - version = Integer.parseInt(values.get(0)); - } catch (NumberFormatException e) { - // Ignore. - } - i = 1; - } else { - i = 0; - } - - if (names.size() <= i) { - // There's a version attribute, but nothing more. - return Collections.emptySet(); - } - - Set cookies = new TreeSet<>(); - for (; i < names.size(); i ++) { - String name = names.get(i); - String value = values.get(i); - if (value == null) { - value = ""; - } - - Cookie c = initCookie(name, value); - - if (c == null) { - break; - } - - boolean discard = false; - boolean secure = false; - boolean httpOnly = false; - String comment = null; - String commentURL = null; - String domain = null; - String path = null; - long maxAge = Long.MIN_VALUE; - List ports = new ArrayList<>(2); - - for (int j = i + 1; j < names.size(); j++, i++) { - name = names.get(j); - value = values.get(j); - - if (DISCARD.equalsIgnoreCase(name)) { - discard = true; - } else if (CookieHeaderNames.SECURE.equalsIgnoreCase(name)) { - secure = true; - } else if (CookieHeaderNames.HTTPONLY.equalsIgnoreCase(name)) { - httpOnly = true; - } else if (COMMENT.equalsIgnoreCase(name)) { - comment = value; - } else if (COMMENTURL.equalsIgnoreCase(name)) { - commentURL = value; - } else if (CookieHeaderNames.DOMAIN.equalsIgnoreCase(name)) { - domain = value; - } else if (CookieHeaderNames.PATH.equalsIgnoreCase(name)) { - path = value; - } else if (CookieHeaderNames.EXPIRES.equalsIgnoreCase(name)) { - Date date = DateFormatter.parseHttpDate(value); - if (date != null) { - long maxAgeMillis = date.getTime() - System.currentTimeMillis(); - maxAge = maxAgeMillis / 1000 + (maxAgeMillis % 1000 != 0? 1 : 0); - } - } else if (CookieHeaderNames.MAX_AGE.equalsIgnoreCase(name)) { - maxAge = Integer.parseInt(value); - } else if (VERSION.equalsIgnoreCase(name)) { - version = Integer.parseInt(value); - } else if (PORT.equalsIgnoreCase(name)) { - String[] portList = value.split(","); - for (String s1: portList) { - try { - ports.add(Integer.valueOf(s1)); - } catch (NumberFormatException e) { - // Ignore. - } - } - } else { - break; - } - } - - c.setVersion(version); - c.setMaxAge(maxAge); - c.setPath(path); - c.setDomain(domain); - c.setSecure(secure); - c.setHttpOnly(httpOnly); - if (version > 0) { - c.setComment(comment); - } - if (version > 1) { - c.setCommentUrl(commentURL); - c.setPorts(ports); - c.setDiscard(discard); - } - - cookies.add(c); - } - - return cookies; - } - - private static void extractKeyValuePairs( - final String header, final List names, final List values) { - final int headerLen = header.length(); - loop: for (int i = 0;;) { - - // Skip spaces and separators. - for (;;) { - if (i == headerLen) { - break loop; - } - switch (header.charAt(i)) { - case '\t': case '\n': case 0x0b: case '\f': case '\r': - case ' ': case ',': case ';': - i ++; - continue; - } - break; - } - - // Skip '$'. - for (;;) { - if (i == headerLen) { - break loop; - } - if (header.charAt(i) == '$') { - i ++; - continue; - } - break; - } - - String name; - String value; - - if (i == headerLen) { - name = null; - value = null; - } else { - int newNameStart = i; - keyValLoop: for (;;) { - switch (header.charAt(i)) { - case ';': - // NAME; (no value till ';') - name = header.substring(newNameStart, i); - value = null; - break keyValLoop; - case '=': - // NAME=VALUE - name = header.substring(newNameStart, i); - i ++; - if (i == headerLen) { - // NAME= (empty value, i.e. nothing after '=') - value = ""; - break keyValLoop; - } - - int newValueStart = i; - char c = header.charAt(i); - if (c == '"' || c == '\'') { - // NAME="VALUE" or NAME='VALUE' - StringBuilder newValueBuf = new StringBuilder(header.length() - i); - final char q = c; - boolean hadBackslash = false; - i ++; - for (;;) { - if (i == headerLen) { - value = newValueBuf.toString(); - break keyValLoop; - } - if (hadBackslash) { - hadBackslash = false; - c = header.charAt(i ++); - switch (c) { - case '\\': case '"': case '\'': - // Escape last backslash. - newValueBuf.setCharAt(newValueBuf.length() - 1, c); - break; - default: - // Do not escape last backslash. - newValueBuf.append(c); - } - } else { - c = header.charAt(i ++); - if (c == q) { - value = newValueBuf.toString(); - break keyValLoop; - } - newValueBuf.append(c); - if (c == '\\') { - hadBackslash = true; - } - } - } - } else { - // NAME=VALUE; - int semiPos = header.indexOf(';', i); - if (semiPos > 0) { - value = header.substring(newValueStart, semiPos); - i = semiPos; - } else { - value = header.substring(newValueStart); - i = headerLen; - } - } - break keyValLoop; - default: - i ++; - } - - if (i == headerLen) { - // NAME (no value till the end of string) - name = header.substring(newNameStart); - value = null; - break; - } - } - } - - names.add(name); - values.add(value); - } - } - - private CookieDecoder(boolean strict) { - this.strict = strict; - } - - private DefaultCookie initCookie(String name, String value) { - if (name == null || name.length() == 0) { - logger.debug("Skipping cookie with null name"); - return null; - } - - if (value == null) { - logger.debug("Skipping cookie with null value"); - return null; - } - - CharSequence unwrappedValue = unwrapValue(value); - if (unwrappedValue == null) { - logger.debug("Skipping cookie because starting quotes are not properly balanced in '{}'", - unwrappedValue); - return null; - } - - int invalidOctetPos; - if (strict && (invalidOctetPos = firstInvalidCookieNameOctet(name)) >= 0) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping cookie because name '{}' contains invalid char '{}'", - name, name.charAt(invalidOctetPos)); - } - return null; - } - - final boolean wrap = unwrappedValue.length() != value.length(); - - if (strict && (invalidOctetPos = firstInvalidCookieValueOctet(unwrappedValue)) >= 0) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping cookie because value '{}' contains invalid char '{}'", - unwrappedValue, unwrappedValue.charAt(invalidOctetPos)); - } - return null; - } - - DefaultCookie cookie = new DefaultCookie(name, unwrappedValue.toString()); - cookie.setWrap(wrap); - return cookie; - } -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/CookieUtil.java b/codec-http/src/main/java/io/netty/handler/codec/http/CookieUtil.java deleted file mode 100644 index fdaae035fd..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/CookieUtil.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2015 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.http; - -import java.util.BitSet; - -/** - * @deprecated Duplicate of package private ${@link io.netty.handler.codec.http.cookie.CookieUtil} - */ -@Deprecated -final class CookieUtil { - - private static final BitSet VALID_COOKIE_VALUE_OCTETS = validCookieValueOctets(); - - private static final BitSet VALID_COOKIE_NAME_OCTETS = validCookieNameOctets(VALID_COOKIE_VALUE_OCTETS); - - // US-ASCII characters excluding CTLs, whitespace, DQUOTE, comma, semicolon, and backslash - private static BitSet validCookieValueOctets() { - BitSet bits = new BitSet(8); - for (int i = 35; i < 127; i++) { - // US-ASCII characters excluding CTLs (%x00-1F / %x7F) - bits.set(i); - } - bits.set('"', false); // exclude DQUOTE = %x22 - bits.set(',', false); // exclude comma = %x2C - bits.set(';', false); // exclude semicolon = %x3B - bits.set('\\', false); // exclude backslash = %x5C - return bits; - } - - // token = 1* - // separators = "(" | ")" | "<" | ">" | "@" - // | "," | ";" | ":" | "\" | <"> - // | "/" | "[" | "]" | "?" | "=" - // | "{" | "}" | SP | HT - private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) { - BitSet bits = new BitSet(8); - bits.or(validCookieValueOctets); - bits.set('(', false); - bits.set(')', false); - bits.set('<', false); - bits.set('>', false); - bits.set('@', false); - bits.set(':', false); - bits.set('/', false); - bits.set('[', false); - bits.set(']', false); - bits.set('?', false); - bits.set('=', false); - bits.set('{', false); - bits.set('}', false); - bits.set(' ', false); - bits.set('\t', false); - return bits; - } - - static int firstInvalidCookieNameOctet(CharSequence cs) { - return firstInvalidOctet(cs, VALID_COOKIE_NAME_OCTETS); - } - - static int firstInvalidCookieValueOctet(CharSequence cs) { - return firstInvalidOctet(cs, VALID_COOKIE_VALUE_OCTETS); - } - - static int firstInvalidOctet(CharSequence cs, BitSet bits) { - for (int i = 0; i < cs.length(); i++) { - char c = cs.charAt(i); - if (!bits.get(c)) { - return i; - } - } - return -1; - } - - static CharSequence unwrapValue(CharSequence cs) { - final int len = cs.length(); - if (len > 0 && cs.charAt(0) == '"') { - if (len >= 2 && cs.charAt(len - 1) == '"') { - // properly balanced - return len == 2 ? "" : cs.subSequence(1, len - 1); - } else { - return null; - } - } - return cs; - } - - private CookieUtil() { - // Unused - } -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java deleted file mode 100644 index ad96bb8899..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.http; - -import java.util.Collections; -import java.util.Set; -import java.util.TreeSet; - -/** - * The default {@link Cookie} implementation. - * - * @deprecated Use {@link io.netty.handler.codec.http.cookie.DefaultCookie} instead. - */ -@Deprecated -public class DefaultCookie extends io.netty.handler.codec.http.cookie.DefaultCookie implements Cookie { - - private String comment; - private String commentUrl; - private boolean discard; - private Set ports = Collections.emptySet(); - private Set unmodifiablePorts = ports; - private int version; - - /** - * Creates a new cookie with the specified name and value. - */ - public DefaultCookie(String name, String value) { - super(name, value); - } - - @Override - @Deprecated - public String getName() { - return name(); - } - - @Override - @Deprecated - public String getValue() { - return value(); - } - - @Override - @Deprecated - public String getDomain() { - return domain(); - } - - @Override - @Deprecated - public String getPath() { - return path(); - } - - @Override - @Deprecated - public String getComment() { - return comment(); - } - - @Override - @Deprecated - public String comment() { - return comment; - } - - @Override - @Deprecated - public void setComment(String comment) { - this.comment = validateValue("comment", comment); - } - - @Override - @Deprecated - public String getCommentUrl() { - return commentUrl(); - } - - @Override - @Deprecated - public String commentUrl() { - return commentUrl; - } - - @Override - @Deprecated - public void setCommentUrl(String commentUrl) { - this.commentUrl = validateValue("commentUrl", commentUrl); - } - - @Override - @Deprecated - public boolean isDiscard() { - return discard; - } - - @Override - @Deprecated - public void setDiscard(boolean discard) { - this.discard = discard; - } - - @Override - @Deprecated - public Set getPorts() { - return ports(); - } - - @Override - @Deprecated - public Set ports() { - if (unmodifiablePorts == null) { - unmodifiablePorts = Collections.unmodifiableSet(ports); - } - return unmodifiablePorts; - } - - @Override - @Deprecated - public void setPorts(int... ports) { - if (ports == null) { - throw new NullPointerException("ports"); - } - - int[] portsCopy = ports.clone(); - if (portsCopy.length == 0) { - unmodifiablePorts = this.ports = Collections.emptySet(); - } else { - Set newPorts = new TreeSet<>(); - for (int p: portsCopy) { - if (p <= 0 || p > 65535) { - throw new IllegalArgumentException("port out of range: " + p); - } - newPorts.add(Integer.valueOf(p)); - } - this.ports = newPorts; - unmodifiablePorts = null; - } - } - - @Override - @Deprecated - public void setPorts(Iterable ports) { - Set newPorts = new TreeSet<>(); - for (int p: ports) { - if (p <= 0 || p > 65535) { - throw new IllegalArgumentException("port out of range: " + p); - } - newPorts.add(Integer.valueOf(p)); - } - if (newPorts.isEmpty()) { - unmodifiablePorts = this.ports = Collections.emptySet(); - } else { - this.ports = newPorts; - unmodifiablePorts = null; - } - } - - @Override - @Deprecated - public long getMaxAge() { - return maxAge(); - } - - @Override - @Deprecated - public int getVersion() { - return version(); - } - - @Override - @Deprecated - public int version() { - return version; - } - - @Override - @Deprecated - public void setVersion(int version) { - this.version = version; - } -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/ServerCookieEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/ServerCookieEncoder.java deleted file mode 100644 index 4b48c6fdba..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/ServerCookieEncoder.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.handler.codec.http; - -import io.netty.handler.codec.http.cookie.ServerCookieDecoder; - -import java.util.Collection; -import java.util.List; - -/** - * A RFC6265 compliant cookie encoder to be used server side, - * so some fields are sent (Version is typically ignored). - * - * As Netty's Cookie merges Expires and MaxAge into one single field, only Max-Age field is sent. - * - * Note that multiple cookies must be sent as separate "Set-Cookie" headers. - * - *
- * // Example
- * {@link HttpResponse} res = ...;
- * res.setHeader("Set-Cookie", {@link ServerCookieEncoder}.encode("JSESSIONID", "1234"));
- * 
- * - * @see ServerCookieDecoder - * - * @deprecated Use {@link io.netty.handler.codec.http.cookie.ServerCookieEncoder} instead - */ -@Deprecated -public final class ServerCookieEncoder { - - /** - * Encodes the specified cookie name-value pair into a Set-Cookie header value. - * - * @param name the cookie name - * @param value the cookie value - * @return a single Set-Cookie header value - */ - @Deprecated - public static String encode(String name, String value) { - return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(name, value); - } - - /** - * Encodes the specified cookie into a Set-Cookie header value. - * - * @param cookie the cookie - * @return a single Set-Cookie header value - */ - @Deprecated - public static String encode(Cookie cookie) { - return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookie); - } - - /** - * Batch encodes cookies into Set-Cookie header values. - * - * @param cookies a bunch of cookies - * @return the corresponding bunch of Set-Cookie headers - */ - @Deprecated - public static List encode(Cookie... cookies) { - return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies); - } - - /** - * Batch encodes cookies into Set-Cookie header values. - * - * @param cookies a bunch of cookies - * @return the corresponding bunch of Set-Cookie headers - */ - @Deprecated - public static List encode(Collection cookies) { - return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies); - } - - /** - * Batch encodes cookies into Set-Cookie header values. - * - * @param cookies a bunch of cookies - * @return the corresponding bunch of Set-Cookie headers - */ - @Deprecated - public static List encode(Iterable cookies) { - return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies); - } - - private ServerCookieEncoder() { - // Unused - } -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/cookie/DefaultCookie.java b/codec-http/src/main/java/io/netty/handler/codec/http/cookie/DefaultCookie.java index cbd54cd092..a53c0a6ee7 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/cookie/DefaultCookie.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/cookie/DefaultCookie.java @@ -194,19 +194,6 @@ public class DefaultCookie implements Cookie { return 0; } - /** - * Validate a cookie attribute value, throws a {@link IllegalArgumentException} otherwise. - * Only intended to be used by {@link io.netty.handler.codec.http.DefaultCookie}. - * @param name attribute name - * @param value attribute value - * @return the trimmed, validated attribute value - * @deprecated CookieUtil is package private, will be removed once old Cookie API is dropped - */ - @Deprecated - protected String validateValue(String name, String value) { - return validateAttributeValue(name, value); - } - @Override public String toString() { StringBuilder buf = stringBuilder()