summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 21:14:13 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 21:14:13 +0000
commit8f1ac0819eeb9bc803637cfd5185a1cff4111234 (patch)
tree36643d2d5f0b3df8306476de28855192c8e0dece /net
parentfdeb7a81b13e68dae850a7d56347fa6a13405815 (diff)
downloadchromium_src-8f1ac0819eeb9bc803637cfd5185a1cff4111234.zip
chromium_src-8f1ac0819eeb9bc803637cfd5185a1cff4111234.tar.gz
chromium_src-8f1ac0819eeb9bc803637cfd5185a1cff4111234.tar.bz2
Make URLRequest store the chain of redirects.
BUG=77942 TEST=url_request_unittest Review URL: http://codereview.chromium.org/6880026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82157 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/url_request/url_request.cc7
-rw-r--r--net/url_request/url_request.h10
-rw-r--r--net/url_request/url_request_unittest.cc28
3 files changed, 36 insertions, 9 deletions
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 3d60137..007c7af 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -112,8 +112,7 @@ void URLRequest::Delegate::OnSetCookie(URLRequest* request,
// URLRequest
URLRequest::URLRequest(const GURL& url, Delegate* delegate)
- : url_(url),
- original_url_(url),
+ : url_chain_(1, url),
method_("GET"),
load_flags_(LOAD_NORMAL),
delegate_(delegate),
@@ -404,7 +403,7 @@ void URLRequest::StartJob(URLRequestJob* job) {
net_log_.BeginEvent(
NetLog::TYPE_URL_REQUEST_START_JOB,
make_scoped_refptr(new URLRequestStartEventParameters(
- url_, method_, load_flags_, priority_)));
+ url(), method_, load_flags_, priority_)));
job_ = job;
job_->SetExtraRequestHeaders(extra_request_headers_);
@@ -619,7 +618,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) {
if (GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure())
referrer_.clear();
- url_ = location;
+ url_chain_.push_back(location);
--redirect_limit_;
if (strip_post_specific_headers) {
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index b25b842..b6d58ce 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -272,8 +272,11 @@ class URLRequest : public base::NonThreadSafe {
// The original url is the url used to initialize the request, and it may
// differ from the url if the request was redirected.
- const GURL& original_url() const { return original_url_; }
- const GURL& url() const { return url_; }
+ const GURL& original_url() const { return url_chain_.front(); }
+ // The chain of urls traversed by this request. If the request had no
+ // redirects, this vector will contain one element.
+ const std::vector<GURL>& url_chain() const { return url_chain_; }
+ const GURL& url() const { return url_chain_.back(); }
// The URL that should be consulted for the third-party cookie blocking
// policy.
@@ -619,8 +622,7 @@ class URLRequest : public base::NonThreadSafe {
scoped_refptr<URLRequestJob> job_;
scoped_refptr<UploadData> upload_;
- GURL url_;
- GURL original_url_;
+ std::vector<GURL> url_chain_;
GURL first_party_for_cookies_;
GURL delegate_redirect_url_;
std::string method_; // "GET", "POST", etc. Should be all uppercase.
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index cabedd4..f32af25 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -337,7 +337,8 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) {
network_delegate.set_redirect_url(redirect_url);
{
- TestURLRequest r(test_server_.GetURL("empty.html"), &d);
+ GURL original_url(test_server_.GetURL("empty.html"));
+ TestURLRequest r(original_url, &d);
scoped_refptr<TestURLRequestContext> context(
new TestURLRequestContext(test_server_.host_port_pair().ToString()));
context->set_network_delegate(&network_delegate);
@@ -349,6 +350,8 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) {
EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
EXPECT_EQ(0, r.status().os_error());
EXPECT_EQ(redirect_url, r.url());
+ EXPECT_EQ(original_url, r.original_url());
+ EXPECT_EQ(2U, r.url_chain().size());
EXPECT_EQ(1, network_delegate.created_requests());
EXPECT_EQ(0, network_delegate.destroyed_requests());
}
@@ -447,6 +450,29 @@ TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) {
EXPECT_EQ(std::string(), req.referrer());
}
+TEST_F(URLRequestTestHTTP, MultipleRedirectTest) {
+ ASSERT_TRUE(test_server_.Start());
+
+ GURL destination_url = test_server_.GetURL("");
+ GURL middle_redirect_url = test_server_.GetURL(
+ "server-redirect?" + destination_url.spec());
+ GURL original_url = test_server_.GetURL(
+ "server-redirect?" + middle_redirect_url.spec());
+ TestDelegate d;
+ TestURLRequest req(original_url, &d);
+ req.Start();
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(1, d.response_started_count());
+ EXPECT_EQ(2, d.received_redirect_count());
+ EXPECT_EQ(destination_url, req.url());
+ EXPECT_EQ(original_url, req.original_url());
+ ASSERT_EQ(3U, req.url_chain().size());
+ EXPECT_EQ(original_url, req.url_chain()[0]);
+ EXPECT_EQ(middle_redirect_url, req.url_chain()[1]);
+ EXPECT_EQ(destination_url, req.url_chain()[2]);
+}
+
class HTTPSRequestTest : public testing::Test {
};