Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: net/http/http_cache_unittest.cc

Issue 339088: Http cache: Always preserve extra headers when dealing with... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_cache.cc ('k') | net/http/partial_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_unittest.cc
===================================================================
--- net/http/http_cache_unittest.cc (revision 30754)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -578,6 +578,10 @@
bool RangeTransactionServer::not_modified_ = false;
bool RangeTransactionServer::modified_ = false;
+// A dummy extra header that must be preserved on a given request.
+// TODO(rvargas): Add tests using this without byte ranges.
+#define EXTRA_HEADER "Extra: header\r\n"
+
// Static.
void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request,
std::string* response_status,
@@ -588,6 +592,12 @@
return;
}
+ // We want to make sure we don't delete extra headers.
+ if (request->extra_headers.find(EXTRA_HEADER) == std::string::npos) {
+ response_status->assign("HTTP/1.1 403 Forbidden");
+ return;
+ }
+
if (not_modified_) {
response_status->assign("HTTP/1.1 304 Not Modified");
return;
@@ -640,7 +650,8 @@
"http://www.google.com/range",
"GET",
base::Time(),
- "Range: bytes = 40-49\r\n",
+ "Range: bytes = 40-49\r\n"
+ EXTRA_HEADER,
net::LOAD_NORMAL,
"HTTP/1.1 206 Partial Content",
"Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n"
@@ -2016,6 +2027,7 @@
MockTransaction transaction(kRangeGET_Transaction);
transaction.request_headers = "If-None-Match: foo\n"
+ EXTRA_HEADER
"Range: bytes = 40-49\n";
RunTransactionTest(cache.http_cache(), transaction);
@@ -2025,6 +2037,7 @@
transaction.request_headers =
"If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\n"
+ EXTRA_HEADER
"Range: bytes = 40-49\n";
RunTransactionTest(cache.http_cache(), transaction);
@@ -2033,6 +2046,7 @@
EXPECT_EQ(0, cache.disk_cache()->create_count());
transaction.request_headers = "If-Range: bla\n"
+ EXTRA_HEADER
"Range: bytes = 40-49\n";
RunTransactionTest(cache.http_cache(), transaction);
@@ -2049,7 +2063,7 @@
// Write to the cache.
MockTransaction transaction(kRangeGET_TransactionOK);
AddMockTransaction(&transaction);
- transaction.request_headers = "";
+ transaction.request_headers = EXTRA_HEADER;
transaction.handler = NULL;
RunTransactionTest(cache.http_cache(), transaction);
@@ -2097,7 +2111,7 @@
// Write to the cache (30-39).
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "Range: bytes = 30-39\r\n";
+ transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER;
transaction.data = "rg: 30-39 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2110,7 +2124,7 @@
MessageLoop::current()->RunAllPending();
// Write and read from the cache (20-59).
- transaction.request_headers = "Range: bytes = 20-59\r\n";
+ transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER;
transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2198,7 +2212,7 @@
// Write to the cache (70-79).
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "Range: bytes = -10\r\n";
+ transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER;
transaction.data = "rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2211,7 +2225,7 @@
MessageLoop::current()->RunAllPending();
// Write and read from the cache (60-79).
- transaction.request_headers = "Range: bytes = 60-\r\n";
+ transaction.request_headers = "Range: bytes = 60-\r\n" EXTRA_HEADER;
transaction.data = "rg: 60-69 rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2238,7 +2252,7 @@
AddMockTransaction(&transaction);
// Write to the cache (70-79).
- transaction.request_headers = "Range: bytes = 70-\r\n";
+ transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER;
transaction.data = "rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2251,7 +2265,7 @@
MessageLoop::current()->RunAllPending();
// Write and read from the cache (60-79).
- transaction.request_headers = "Range: bytes = -20\r\n";
+ transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER;
transaction.data = "rg: 60-69 rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2277,7 +2291,7 @@
handler.set_not_modified(true);
// Ask for the end of the file, without knowing the length.
- transaction.request_headers = "Range: bytes = 70-\r\n";
+ transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER;
transaction.data = "rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2311,7 +2325,7 @@
// Write and read from the cache (0-79), when not asked for a range.
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "";
+ transaction.request_headers = EXTRA_HEADER;
transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
"rg: 50-59 rg: 60-69 rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2331,7 +2345,7 @@
cache.http_cache()->set_enable_range_support(true);
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "Range: bytes = 0-9\r\n";
+ transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER;
transaction.data = "rg: 00-09 ";
AddMockTransaction(&transaction);
std::string headers;
@@ -2346,7 +2360,7 @@
// Read from the cache (0-9), write and read from cache (10 - 79),
MockTransaction transaction2(kRangeGET_TransactionOK);
- transaction2.request_headers = "Foo: bar\r\n";
+ transaction2.request_headers = "Foo: bar\r\n" EXTRA_HEADER;
transaction2.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
"rg: 50-59 rg: 60-69 rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers);
@@ -2501,7 +2515,7 @@
// Write to the cache (70-79).
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "Range: bytes = -10\r\n";
+ transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER;
transaction.data = "rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
@@ -2551,7 +2565,7 @@
// A weird request should not delete this entry. Ask for bytes 120-.
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "Range: bytes = 120-\r\n";
+ transaction.request_headers = "Range: bytes = 120-\r\n" EXTRA_HEADER;
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
EXPECT_EQ(0U, headers.find("HTTP/1.1 416 "));
@@ -2717,7 +2731,7 @@
MockTransaction transaction(kRangeGET_TransactionOK);
transaction.handler = NULL;
- transaction.request_headers = "Range: bytes = 50-59\r\n";
+ transaction.request_headers = "Range: bytes = 50-59\r\n" EXTRA_HEADER;
std::string response_headers(transaction.response_headers);
response_headers.append("Content-Range: bytes 50-59/160\n");
transaction.response_headers = response_headers.c_str();
@@ -2764,7 +2778,8 @@
MockTransaction transaction(kRangeGET_TransactionOK);
transaction.handler = NULL;
- transaction.request_headers = "Range: bytes = 4294967288-4294967297\r\n";
+ transaction.request_headers = "Range: bytes = 4294967288-4294967297\r\n"
+ EXTRA_HEADER;
transaction.response_headers =
"Content-Range: bytes 4294967288-4294967297/4294967299\n"
"Content-Length: 10\n";
@@ -2968,7 +2983,7 @@
// Now make a regular request.
std::string headers;
MockTransaction transaction(kRangeGET_TransactionOK);
- transaction.request_headers = "";
+ transaction.request_headers = EXTRA_HEADER;
transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
"rg: 50-59 rg: 60-69 rg: 70-79 ";
RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
« no previous file with comments | « net/http/http_cache.cc ('k') | net/http/partial_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698