Auto merge of #18676 - gterzian:continue_http_cache_work, r=jdm

Continue http cache work

<!-- Please describe your changes on the following line: -->

Work in progress, and not quite worth a review yet. (Continuation of https://github.com/servo/servo/pull/4117)

TODO

- [ ] cache metadata (find some subset of`net_traits::Metadata` that can be shared across threads, it seems the problem is mainly stuff inside `hyper::header` in the `headers` field)

- [ ] determine which other fields of a `Response` need to be cached, so a full and valid one can be returned upon a cache hit.

- [ ] determine how to best share the cache across fetch threads (inside HttpState like I tried now?)

- [ ] Spend more time reading the spec and make sure the cache follows it where it matters.

- [ ] Make the current wpt tests pass.

- [ ] More...

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #12972  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18676)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-20 18:22:06 -06:00 committed by GitHub
commit e2bc0f017c
37 changed files with 1238 additions and 631 deletions

View file

@ -201,7 +201,8 @@
request_headers: [
["Cache-Control", "only-if-cached"]
],
expected_status: 504
expected_status: 504,
expected_response_text: ""
}
]
}

View file

@ -26,6 +26,7 @@
},
{
expected_type: "cached",
response_status: [299, "Whatever"],
}
]
},
@ -35,8 +36,7 @@
{
response_status: [299, "Whatever"],
response_headers: [
['Last-Modified', http_date(-3 * 100)],
['Cache-Control', 'public']
['Last-Modified', http_date(-3 * 100)]
],
},
{

View file

@ -24,7 +24,7 @@
response_status: [206, "Partial Content"],
response_headers: [
['Cache-Control', 'max-age=3600'],
['Content-Range', 'bytes 0-4/10']
['Content-Range', 'bytes 4-9/10']
],
response_body: "01234",
expected_request_headers: [
@ -36,12 +36,13 @@
['Range', "bytes=-5"]
],
expected_type: "cached",
expected_status: 206
expected_status: 206,
expected_response_text: "01234"
}
]
},
{
name: 'HTTP cache stores complete response and serves smaller ranges from it.',
name: 'HTTP cache stores complete response and serves smaller ranges from it(byte-range-spec).',
requests: [
{
response_headers: [
@ -51,15 +52,54 @@
},
{
request_headers: [
['Range', "bytes=-1"]
['Range', "bytes=0-1"]
],
expected_type: "cached",
expected_status: 206,
expected_response_text: "01"
},
]
},
{
name: 'HTTP cache stores complete response and serves smaller ranges from it(absent last-byte-pos).',
requests: [
{
response_headers: [
['Cache-Control', 'max-age=3600'],
],
response_body: "01234567890",
},
{
request_headers: [
['Range', "bytes=1-"]
],
expected_type: "cached",
expected_status: 206,
expected_response_text: "1234567890"
}
]
},
{
name: 'HTTP cache stores partial response and serves smaller ranges from it.',
name: 'HTTP cache stores complete response and serves smaller ranges from it(suffix-byte-range-spec).',
requests: [
{
response_headers: [
['Cache-Control', 'max-age=3600'],
],
response_body: "0123456789A",
},
{
request_headers: [
['Range', "bytes=-1"]
],
expected_type: "cached",
expected_status: 206,
expected_response_text: "A"
}
]
},
{
name: 'HTTP cache stores partial response and serves smaller ranges from it(byte-range-spec).',
requests: [
{
request_headers: [
@ -68,7 +108,55 @@
response_status: [206, "Partial Content"],
response_headers: [
['Cache-Control', 'max-age=3600'],
['Content-Range', 'bytes 0-4/10']
['Content-Range', 'bytes 4-9/10']
],
response_body: "01234",
},
{
request_headers: [
['Range', "bytes=6-8"]
],
expected_type: "cached",
expected_status: 206,
expected_response_text: "234"
}
]
},
{
name: 'HTTP cache stores partial response and serves smaller ranges from it(absent last-byte-pos).',
requests: [
{
request_headers: [
['Range', "bytes=-5"]
],
response_status: [206, "Partial Content"],
response_headers: [
['Cache-Control', 'max-age=3600'],
['Content-Range', 'bytes 4-9/10']
],
response_body: "01234",
},
{
request_headers: [
['Range', "bytes=6-"]
],
expected_type: "cached",
expected_status: 206,
expected_response_text: "234"
}
]
},
{
name: 'HTTP cache stores partial response and serves smaller ranges from it(suffix-byte-range-spec).',
requests: [
{
request_headers: [
['Range', "bytes=-5"]
],
response_status: [206, "Partial Content"],
response_headers: [
['Cache-Control', 'max-age=3600'],
['Content-Range', 'bytes 4-9/10']
],
response_body: "01234",
},
@ -77,7 +165,8 @@
['Range', "bytes=-1"]
],
expected_type: "cached",
expected_response_text: "01"
expected_status: 206,
expected_response_text: "4"
}
]
},

View file

@ -103,6 +103,7 @@
request_headers: [
["Foo", "1"]
],
response_body: http_content('foo_1'),
expected_type: "cached"
}
]
@ -245,7 +246,32 @@
]
},
{
name: "HTTP cache doesn't use three-way Vary response when request omits variant header.",
name: "HTTP cache doesn't use three-way Vary response when request doesn't match, regardless of header order.",
requests: [
{
request_headers: [
["Foo", "1"],
["Bar", "abc4"],
["Baz", "789"]
],
response_headers: [
["Expires", http_date(5000)],
["Last-Modified", http_date(-3000)],
["Vary", "Foo, Bar, Baz"]
]
},
{
request_headers: [
["Foo", "1"],
["Bar", "abc"],
["Baz", "789"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache uses three-way Vary response when both request and the original request omited a variant header.",
requests: [
{
request_headers: [
@ -259,6 +285,33 @@
]
},
{
request_headers: [
["Foo", "1"],
["Baz", "789"]
],
expected_type: "cached"
}
]
},
{
name: "HTTP cache doesn't use Vary response with a field value of '*'.",
requests: [
{
request_headers: [
["Foo", "1"],
["Baz", "789"]
],
response_headers: [
["Expires", http_date(5000)],
["Last-Modified", http_date(-3000)],
["Vary", "*"]
]
},
{
request_headers: [
["*", "1"],
["Baz", "789"]
],
expected_type: "not_cached"
}
]