2011-05-11 10:02:11 +02:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2011-05-11 10:02:11 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01:00
|
|
|
* 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:
|
2011-05-11 10:02:11 +02:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-05-11 10:02:11 +02:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2011-05-11 10:02:11 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.handler.codec.http;
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2014-06-17 11:37:58 +02:00
|
|
|
import io.netty.util.concurrent.FastThreadLocal;
|
2016-11-21 21:29:44 +01:00
|
|
|
import io.netty.handler.codec.DateFormatter;
|
2014-06-09 02:18:46 +02:00
|
|
|
|
2011-05-11 10:02:11 +02:00
|
|
|
import java.text.ParsePosition;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This DateFormat decodes 3 formats of {@link Date}, but only encodes the one,
|
|
|
|
* the first:
|
|
|
|
* <ul>
|
|
|
|
* <li>Sun, 06 Nov 1994 08:49:37 GMT: standard specification, the only one with
|
|
|
|
* valid generation</li>
|
RFC6265 cookies support
Motivation:
Currently Netty supports a weird implementation of RFC 2965.
First, this RFC has been deprecated by RFC 6265 and nobody on the
internet use this format.
Then, there's a confusion between client side and server side encoding
and decoding.
Typically, clients should only send name=value pairs.
This PR introduces RFC 6265 support, but keeps on supporting RFC 2965 in
the sense that old unused fields are simply ignored, and Cookie fields
won't be populated. Deprecated fields are comment, commentUrl, version,
discard and ports.
It also provides a mechanism for safe server-client-server roundtrip, as
User-Agents are not supposed to interpret cookie values but return them
as-is (e.g. if Set-Cookie contained a quoted value, it should be sent
back in the Cookie header in quoted form too).
Also, there are performance gains to be obtained by not allocating the
attribute name Strings, as we only want to match them to find which POJO
field to populate.
Modifications:
- New RFC6265ClientCookieEncoder/Decoder and
RFC6265ServerCookieEncoder/Decoder pairs that live alongside old
CookieEncoder/Decoder pair to not break backward compatibility.
- New Cookie.rawValue field, used for lossless server-client-server
roundtrip.
Result:
RFC 6265 support.
Clean separation of client and server side.
Decoder performance gain:
Benchmark Mode Samples Score Error
Units
parseOldClientDecoder thrpt 20 2070169,228 ± 105044,970
ops/s
parseRFC6265ClientDecoder thrpt 20 2954015,476 ± 126670,633
ops/s
This commit closes #3221 and #1406.
2015-01-19 15:06:35 +01:00
|
|
|
* <li>Sunday, 06-Nov-94 08:49:37 GMT: obsolete specification</li>
|
|
|
|
* <li>Sun Nov 6 08:49:37 1994: obsolete specification</li>
|
2011-05-11 10:02:11 +02:00
|
|
|
* </ul>
|
2016-11-21 21:29:44 +01:00
|
|
|
* @deprecated Use {@link DateFormatter} instead
|
2011-05-11 10:02:11 +02:00
|
|
|
*/
|
2016-11-14 12:33:03 +01:00
|
|
|
@Deprecated
|
2015-04-14 13:57:32 +02:00
|
|
|
public final class HttpHeaderDateFormat extends SimpleDateFormat {
|
2011-05-11 11:09:49 +02:00
|
|
|
private static final long serialVersionUID = -925286159755905325L;
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
private final SimpleDateFormat format1 = new HttpHeaderDateFormatObsolete1();
|
|
|
|
private final SimpleDateFormat format2 = new HttpHeaderDateFormatObsolete2();
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2014-06-17 11:37:58 +02:00
|
|
|
private static final FastThreadLocal<HttpHeaderDateFormat> dateFormatThreadLocal =
|
2014-06-09 02:18:46 +02:00
|
|
|
new FastThreadLocal<HttpHeaderDateFormat>() {
|
2013-07-07 05:39:29 +02:00
|
|
|
@Override
|
|
|
|
protected HttpHeaderDateFormat initialValue() {
|
|
|
|
return new HttpHeaderDateFormat();
|
|
|
|
}
|
|
|
|
};
|
2013-05-23 11:39:50 +02:00
|
|
|
|
2015-04-14 13:57:32 +02:00
|
|
|
public static HttpHeaderDateFormat get() {
|
2013-05-23 11:39:50 +02:00
|
|
|
return dateFormatThreadLocal.get();
|
|
|
|
}
|
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
/**
|
|
|
|
* Standard date format<p>
|
|
|
|
* Sun, 06 Nov 1994 08:49:37 GMT -> E, d MMM yyyy HH:mm:ss z
|
|
|
|
*/
|
2013-05-23 11:39:50 +02:00
|
|
|
private HttpHeaderDateFormat() {
|
2011-05-11 11:09:49 +02:00
|
|
|
super("E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
|
|
|
|
setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
}
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
@Override
|
|
|
|
public Date parse(String text, ParsePosition pos) {
|
|
|
|
Date date = super.parse(text, pos);
|
|
|
|
if (date == null) {
|
|
|
|
date = format1.parse(text, pos);
|
|
|
|
}
|
|
|
|
if (date == null) {
|
|
|
|
date = format2.parse(text, pos);
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
}
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
/**
|
|
|
|
* First obsolete format<p>
|
|
|
|
* Sunday, 06-Nov-94 08:49:37 GMT -> E, d-MMM-y HH:mm:ss z
|
|
|
|
*/
|
2011-11-10 03:45:42 +01:00
|
|
|
private static final class HttpHeaderDateFormatObsolete1 extends SimpleDateFormat {
|
2011-05-11 11:09:49 +02:00
|
|
|
private static final long serialVersionUID = -3178072504225114298L;
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
HttpHeaderDateFormatObsolete1() {
|
2013-05-22 11:27:04 +02:00
|
|
|
super("E, dd-MMM-yy HH:mm:ss z", Locale.ENGLISH);
|
2011-05-11 11:09:49 +02:00
|
|
|
setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
}
|
|
|
|
}
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
/**
|
|
|
|
* Second obsolete format
|
|
|
|
* <p>
|
|
|
|
* Sun Nov 6 08:49:37 1994 -> EEE, MMM d HH:mm:ss yyyy
|
|
|
|
*/
|
2011-11-10 03:45:42 +01:00
|
|
|
private static final class HttpHeaderDateFormatObsolete2 extends SimpleDateFormat {
|
2011-05-11 11:09:49 +02:00
|
|
|
private static final long serialVersionUID = 3010674519968303714L;
|
2011-05-11 10:02:11 +02:00
|
|
|
|
2011-05-11 11:09:49 +02:00
|
|
|
HttpHeaderDateFormatObsolete2() {
|
|
|
|
super("E MMM d HH:mm:ss yyyy", Locale.ENGLISH);
|
|
|
|
setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
}
|
|
|
|
}
|
2011-05-11 10:02:11 +02:00
|
|
|
}
|