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.
This commit is contained in:
Robert Budźko 2016-04-28 23:34:10 +02:00 committed by Konrad Malawski
parent c72890b113
commit fbe383722c
4 changed files with 23 additions and 5 deletions

View file

@ -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 {

View file

@ -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,

View file

@ -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" =!=

View file

@ -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")
)
)
}