Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/src/main/paradox/client-side/request-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ to direct the request to.

## Collecting headers from a server response

Sometimes we would like to get only headers of specific type which are sent from a server. In order to collect headers in a type safe way Apache Pekko HTTP API provides a type for each HTTP header. Here is an example for getting all cookies set by a server (`Set-Cookie` header):
Sometimes we would like to get only headers of specific type which are sent from a server. In order to collect headers in a type safe way Apache Pekko HTTP API provides a type for each HTTP header. Cookie expiry dates in the supported legacy date formats also accept the `-0000` UTC suffix and are rendered with `GMT`. This does not change parsing of the HTTP `Date` or `Expires` headers.

Here is an example for getting all cookies set by a server (`Set-Cookie` header):

Scala
: @@snip [HttpClientExampleSpec.scala](/docs/src/test/scala/docs/http/scaladsl/HttpClientCollectingHeaders.scala)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,25 @@ private[parser] trait CommonRules extends StringBuilding { this: Parser =>
ignoreCase("expires=") ~ OWS ~ `cookie-expires-date` ~> { (c: HttpCookie, dt: DateTime) => c.withExpires(dt) }
}

// Cookie receivers accept one or two digits per time component (RFC 6265, section 5.1.1).
// Cookie receivers accept one or two digits per time component and interpret dates as UTC (RFC 6265, section 5.1.1).
// Keep this separate from HTTP-date: this only extends the existing date shapes, not the full token algorithm.
def `cookie-expires-date`: Rule1[DateTime] = rule {
(`HTTP-date` | `cookie-IMF-fixdate` | `cookie-asctime-date` |
(`cookie-IMF-fixdate` | `cookie-asctime-date` | `HTTP-date` |
zeroOrMore(ANY) ~ push(DateTime.MinValue)) ~ OWS
}

def `cookie-time-of-day` = rule { (digit2 | digit) ~ ':' ~ (digit2 | digit) ~ ':' ~ (digit2 | digit) }

def `cookie-IMF-fixdate` = rule {
(`day-name-l` | `day-name`) ~ ", " ~ (date1 | date2) ~ ' ' ~ `cookie-time-of-day` ~ ' ' ~ ("GMT" | "UTC") ~> {
(`day-name-l` | `day-name`) ~ ", " ~
(date1 | date2) ~ ' ' ~ `cookie-time-of-day` ~ ' ' ~
("GMT" | "UTC" | "-0000") ~> {
(wkday, day, month, year, hour, min, sec) => createDateTime(year, month, day, hour, min, sec, wkday)
}
}

def `cookie-asctime-date` = rule {
`day-name` ~ ' ' ~ date3 ~ ' ' ~ `cookie-time-of-day` ~ ' ' ~ year ~> {
`day-name` ~ ' ' ~ date3 ~ ' ' ~ `cookie-time-of-day` ~ ' ' ~ year ~ optional(" -0000") ~> {
(wkday, month, day, hour, min, sec, year) => createDateTime(year, month, day, hour, min, sec, wkday)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ class HttpHeaderSpec extends AnyFreeSpec with Matchers {
val `application/vnd.spray` = MediaType.applicationBinary("vnd.spray", MediaType.Compressible)
val PROPFIND = HttpMethod.custom("PROPFIND")

for (date <- Seq(
"Sun, 06 Nov 1994 08:09:07 -0000",
"Sunday, 06-Nov-94 08:09:07 -0000",
"Sun Nov 06 08:09:07 1994 -0000",
"Sun, 06 Nov 1994 8:9:7 -0000",
"Sun Nov 06 8:9:7 1994 -0000")) {
s"cookie expiry zero-offset suffix $date" in {
s"Set-Cookie: sid=value; Expires=$date; Path=/" =!=
`Set-Cookie`(HttpCookie("sid", "value", expires = Some(DateTime(1994, 11, 6, 8, 9, 7)), path = Some("/")))
.renderedTo("sid=value; Expires=Sun, 06 Nov 1994 08:09:07 GMT; Path=/")
}
}

for ((time, hour, minute, second) <- Seq(
("08:09:07", 8, 9, 7), ("8:9:7", 8, 9, 7), ("8:09:07", 8, 9, 7),
("08:9:07", 8, 9, 7), ("08:09:7", 8, 9, 7), ("0:0:0", 0, 0, 0), ("23:59:59", 23, 59, 59))) {
Expand Down
Loading