From fbe383722c6d3402ced2b4422efa38446c23e1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Bud=C5=BAko?= Date: Thu, 28 Apr 2016 23:34:10 +0200 Subject: [PATCH] htc #20362 Expire defaults when HTTP-date is not possible to parse (#20362) * Expire defaults when HTTP-date is not possible to parse (#20362) and 'If-Modified-Since' is more strict (excluding 0 - rfc 7232 3.3). * Fixed reversed missing method MiMa problem (#20131) and 'expires' instead of 'expire' wording. * HTTP-date should match '0' as DateTime.MinValue after all. --- .../akka/http/impl/model/parser/CommonRules.scala | 10 +++++++++- .../akka/http/impl/model/parser/SimpleHeaders.scala | 2 +- .../akka/http/impl/model/parser/HttpHeaderSpec.scala | 11 +++++++++-- project/MiMa.scala | 5 ++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/akka-http-core/src/main/scala/akka/http/impl/model/parser/CommonRules.scala b/akka-http-core/src/main/scala/akka/http/impl/model/parser/CommonRules.scala index 7552cc130b..d000081242 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/model/parser/CommonRules.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/model/parser/CommonRules.scala @@ -60,6 +60,14 @@ private[parser] trait CommonRules { this: Parser with StringBuilding ⇒ def `quoted-cpair` = `quoted-pair` + // ****************************************************************************************** + // http://tools.ietf.org/html/rfc7234#section-5.3 + // ****************************************************************************************** + + def `expires-date`: Rule1[DateTime] = rule { + (`HTTP-date` | zeroOrMore(ANY) ~ push(DateTime.MinValue)) ~ OWS + } + // ****************************************************************************************** // http://tools.ietf.org/html/rfc7231#section-7.1.1.1 // but more lenient where we have already seen differing implementations in the field @@ -251,7 +259,7 @@ private[parser] trait CommonRules { this: Parser with StringBuilding ⇒ } def `expires-av` = rule { - ignoreCase("expires=") ~ OWS ~ `HTTP-date` ~> { (c: HttpCookie, dt: DateTime) ⇒ c.copy(expires = Some(dt)) } + ignoreCase("expires=") ~ OWS ~ `expires-date` ~> { (c: HttpCookie, dt: DateTime) ⇒ c.copy(expires = Some(dt)) } } def `max-age-av` = rule { diff --git a/akka-http-core/src/main/scala/akka/http/impl/model/parser/SimpleHeaders.scala b/akka-http-core/src/main/scala/akka/http/impl/model/parser/SimpleHeaders.scala index d7d2ee72e2..a269c701d1 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/model/parser/SimpleHeaders.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/model/parser/SimpleHeaders.scala @@ -121,7 +121,7 @@ private[parser] trait SimpleHeaders { this: Parser with CommonRules with CommonA } // http://tools.ietf.org/html/rfc7234#section-5.3 - def `expires` = rule { `HTTP-date` ~ EOI ~> (Expires(_)) } + def `expires` = rule { `expires-date` ~ EOI ~> (Expires(_)) } // http://tools.ietf.org/html/rfc7230#section-5.4 // We don't accept scoped IPv6 addresses as they should not appear in the Host header, diff --git a/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala index 38153160dc..51e213a5de 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala @@ -279,6 +279,9 @@ class HttpHeaderSpec extends FreeSpec with Matchers { "Expires" in { "Expires: Wed, 13 Jul 2011 08:12:31 GMT" =!= Expires(DateTime(2011, 7, 13, 8, 12, 31)) "Expires: 0" =!= Expires(DateTime.MinValue).renderedTo("Wed, 01 Jan 1800 00:00:00 GMT") + "Expires: -1" =!= Expires(DateTime.MinValue).renderedTo("Wed, 01 Jan 1800 00:00:00 GMT") + "Expires: " =!= Expires(DateTime.MinValue).renderedTo("Wed, 01 Jan 1800 00:00:00 GMT") + "Expires: batman" =!= Expires(DateTime.MinValue).renderedTo("Wed, 01 Jan 1800 00:00:00 GMT") } "Host" in { @@ -505,9 +508,13 @@ class HttpHeaderSpec extends FreeSpec with Matchers { ErrorInfo("Illegal HTTP header 'Set-Cookie': Illegal weekday in date 2014-12-13T00:42:55", "is 'Mon' but should be 'Sat'") "Set-Cookie: lang=; Expires=xxxx" =!= + `Set-Cookie`(HttpCookie("lang", "", expires = Some(DateTime.MinValue))) + .renderedTo("lang=; Expires=Wed, 01 Jan 1800 00:00:00 GMT") + + "Set-Cookie: lang=; domain=----" =!= ErrorInfo( - "Illegal HTTP header 'Set-Cookie': Invalid input 'x', expected OWS or HTTP-date (line 1, column 16)", - "lang=; Expires=xxxx\n ^") + "Illegal HTTP header 'Set-Cookie': Invalid input '-', expected OWS or domain-value (line 1, column 15)", + "lang=; domain=----\n ^") // extra examples from play "Set-Cookie: PLAY_FLASH=\"success=found\"; Path=/; HTTPOnly" =!= diff --git a/project/MiMa.scala b/project/MiMa.scala index 8cd7f6e433..b7ab9ad626 100644 --- a/project/MiMa.scala +++ b/project/MiMa.scala @@ -764,7 +764,10 @@ object MiMa extends AutoPlugin { // internal api FilterAnyProblemStartingWith("akka.stream.impl"), FilterAnyProblemStartingWith("akka.http.impl.engine.parsing.BodyPartParser"), - ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.impl.util.package.printEvent") + ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.impl.util.package.printEvent"), + + // #20362 - parser private + ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.impl.model.parser.CommonRules.expires-date") ) ) }