Browse Source

2009-07-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Set referer and method to newly created Request object.
	* src/CreateRequestCommand.cc
	* src/FileEntry.cc
	* src/FileEntry.h
Tatsuhiro Tsujikawa 16 years ago
parent
commit
47309df04d
4 changed files with 32 additions and 4 deletions
  1. 7 0
      ChangeLog
  2. 9 1
      src/CreateRequestCommand.cc
  3. 6 1
      src/FileEntry.cc
  4. 10 2
      src/FileEntry.h

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2009-07-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Set referer and method to newly created Request object.
+	* src/CreateRequestCommand.cc
+	* src/FileEntry.cc
+	* src/FileEntry.h
+
 2009-07-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Removed ctor of AbstractCommand which doesn't take FileEntry.

+ 9 - 1
src/CreateRequestCommand.cc

@@ -42,6 +42,8 @@
 #include "DownloadEngine.h"
 #include "SocketCore.h"
 #include "SegmentMan.h"
+#include "prefs.h"
+#include "Option.h"
 
 namespace aria2 {
 
@@ -65,7 +67,13 @@ bool CreateRequestCommand::executeInternal()
     _fileEntry = _requestGroup->getDownloadContext()->findFileEntryByOffset
       (_segments.front()->getPositionToWrite());
   }
-  req = _fileEntry->getRequest(_requestGroup->getURISelector());
+  req = _fileEntry->getRequest(_requestGroup->getURISelector(),
+			       getOption()->get(PREF_REFERER),
+			       // Don't use HEAD request when file
+			       // size is known.
+			       _fileEntry->getLength() == 0 &&
+			       getOption()->getAsBool(PREF_USE_HEAD)?
+			       Request::METHOD_HEAD:Request::METHOD_GET);
   if(req.isNull()) {
     if(!_requestGroup->getSegmentMan().isNull()) {
       _requestGroup->getSegmentMan()->ignoreSegmentFor(_fileEntry);

+ 6 - 1
src/FileEntry.cc

@@ -118,7 +118,10 @@ static bool inFlightHost(InputIterator first, InputIterator last,
 }
 
 SharedHandle<Request>
-FileEntry::getRequest(const SharedHandle<URISelector>& selector)
+FileEntry::getRequest
+(const SharedHandle<URISelector>& selector,
+ const std::string& referer,
+ const std::string& method)
 {
   SharedHandle<Request> req;
   if(_requestPool.empty()) {
@@ -138,6 +141,8 @@ FileEntry::getRequest(const SharedHandle<URISelector>& selector)
 	    continue;
 	  }
 	}
+	req->setReferer(referer);
+	req->setMethod(method);
 	_spentUris.push_back(uri);
 	_inFlightRequests.push_back(req);
 	break;

+ 10 - 2
src/FileEntry.h

@@ -46,6 +46,7 @@
 #include "Request.h"
 #include "URIResult.h"
 #include "DownloadResultCode.h"
+#include "A2STR.h"
 
 namespace aria2 {
 
@@ -163,8 +164,15 @@ public:
   // If pooled Request object is available, one of them is removed
   // from the pool and returned.  If pool is empty, then select URI
   // using selectUri(selector) and construct Request object using it
-  // and return the Request object.
-  SharedHandle<Request> getRequest(const SharedHandle<URISelector>& selector);
+  // and return the Request object.  If referer is given, it is set to
+  // newly created Request. If Request object is retrieved from the
+  // pool, referer is ignored.  If method is given, it is set to newly
+  // created Request. If Request object is retrieved from the pool,
+  // method is ignored.
+  SharedHandle<Request> getRequest
+  (const SharedHandle<URISelector>& selector,
+   const std::string& referer = A2STR::NIL,
+   const std::string& method = Request::METHOD_GET);
 
   // Finds pooled Request object which is faster than passed one,
   // comparing their PeerStat objects. If such Request is found, it is