From 3080af7370f97b088663ce3dfdcb2a3dfbdf9498 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 1 Oct 2013 21:53:28 +0900 Subject: [PATCH] Request: Remove previousUri_ Historically, the previousUri_ has different meaning from referer_, but in the course of development, they have the same value. This change remove previousUri_ in favor of referer_. --- src/HttpRequest.cc | 9 ++------- src/HttpRequest.h | 2 -- src/Request.cc | 3 +-- src/Request.h | 7 +------ test/RequestTest.cc | 24 ++---------------------- 5 files changed, 6 insertions(+), 39 deletions(-) diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index efcde2c1..d6f6d16b 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -224,8 +224,8 @@ std::string HttpRequest::createRequest() val += base64::encode(authText.begin(), authText.end()); builtinHds.push_back(std::make_pair("Authorization:", val)); } - if(!getPreviousURI().empty()) { - builtinHds.push_back(std::make_pair("Referer:", getPreviousURI())); + if(!request_->getReferer().empty()) { + builtinHds.push_back(std::make_pair("Referer:", request_->getReferer())); } if(cookieStorage_) { std::string cookiesValue; @@ -411,11 +411,6 @@ const std::string& HttpRequest::getQuery() const return request_->getQuery(); } -const std::string& HttpRequest::getPreviousURI() const -{ - return request_->getPreviousUri(); -} - std::string HttpRequest::getURIHost() const { return request_->getURIHost(); diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 38fe9986..3baac4bb 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -131,8 +131,6 @@ public: const std::string& getQuery() const; - const std::string& getPreviousURI() const; - std::string getURIHost() const; Range getRange() const; diff --git a/src/Request.cc b/src/Request.cc index ad7b934f..09890c1f 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -84,7 +84,6 @@ bool Request::setUri(const std::string& uri) { } bool Request::resetUri() { - previousUri_ = referer_; supportsPersistentConnection_ = true; setConnectedAddrInfo(A2STR::NIL, A2STR::NIL, 0); return parseUri(uri_); @@ -92,7 +91,7 @@ bool Request::resetUri() { void Request::setReferer(const std::string& uri) { - referer_ = previousUri_ = removeFragment(uri); + referer_ = removeFragment(uri); } bool Request::redirectUri(const std::string& uri) { diff --git a/src/Request.h b/src/Request.h index 24850584..1dc62617 100644 --- a/src/Request.h +++ b/src/Request.h @@ -52,11 +52,7 @@ private: std::string uri_; std::string currentUri_; /** - * URI previously requested to the server. This is used as Referer - */ - std::string previousUri_; - /** - * URI used as Referer in the initial request + * URI used as Referer header field */ std::string referer_; std::string method_; @@ -97,7 +93,6 @@ public: // Returns URI passed by setUri() const std::string& getUri() const { return uri_; } const std::string& getCurrentUri() const { return currentUri_; } - const std::string& getPreviousUri() const { return previousUri_; } const std::string& getReferer() const { return referer_; } void setReferer(const std::string& uri); const std::string& getProtocol() const { return us_.protocol; } diff --git a/test/RequestTest.cc b/test/RequestTest.cc index 78c41641..76d0ec7b 100644 --- a/test/RequestTest.cc +++ b/test/RequestTest.cc @@ -55,7 +55,7 @@ void RequestTest::testSetUri1() { req.getUri()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getCurrentUri()); - CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri()); + CPPUNIT_ASSERT_EQUAL(std::string(""), req.getReferer()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); @@ -77,8 +77,6 @@ void RequestTest::testSetUri2() { // referer is unchaged CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080"), req.getReferer()); - // previousUri must equal to referer; - CPPUNIT_ASSERT_EQUAL(req.getReferer(), req.getPreviousUri()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); @@ -116,8 +114,6 @@ void RequestTest::testRedirectUri() // currentUri must be updated CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/"), req.getCurrentUri()); - // previousUri is "" because no referer is set. - CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.co.jp"), req.getHost()); CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); @@ -156,25 +152,12 @@ void RequestTest::testRedirectUri2() { Request req; req.setUri("http://aria.rednoah.com/download.html"); - CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri()); req.setReferer("http://aria.rednoah.com/"); - // previousUri is updated when referer is specified - CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), - req.getPreviousUri()); req.redirectUri("http://aria.rednoah.com/403.html"); - // previousUri must not be changed in redirection - CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), - req.getPreviousUri()); - // referer is unchagned + // referer must not be changed in redirection CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getReferer()); - - req.redirectUri("http://aria.rednoah.com/error.html"); - - // previousUri must not be changed in redirection - CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), - req.getPreviousUri()); } void RequestTest::testResetUri() @@ -191,9 +174,6 @@ void RequestTest::testResetUri() (std::string("http://aria.rednoah.com:8080/aria2/index.html"), req.getUri()); CPPUNIT_ASSERT_EQUAL(req.getUri(), req.getCurrentUri()); - // previousUri must equal to referer - CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), - req.getPreviousUri()); // referer is unchanged CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), req.getReferer());