Bladeren bron

2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Made string listeral to static const std::string.
	* src/HttpConnection.cc
	* src/HttpHeader.cc
	* src/HttpHeader.h
	* src/HttpResponse.cc
Tatsuhiro Tsujikawa 17 jaren geleden
bovenliggende
commit
00f385c3b3
5 gewijzigde bestanden met toevoegingen van 63 en 14 verwijderingen
  1. 8 0
      ChangeLog
  2. 2 2
      src/HttpConnection.cc
  3. 20 0
      src/HttpHeader.cc
  4. 20 0
      src/HttpHeader.h
  5. 13 12
      src/HttpResponse.cc

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-05-14  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Made string listeral to static const std::string.
+	* src/HttpConnection.cc
+	* src/HttpHeader.cc
+	* src/HttpHeader.h
+	* src/HttpResponse.cc
+
 2008-05-14  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Made string listeral to static const std::string.

+ 2 - 2
src/HttpConnection.cc

@@ -138,8 +138,8 @@ HttpResponseHandle HttpConnection::receiveResponse()
   //   Connection: close is received or the remote server is not HTTP/1.1.
   // We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
   SharedHandle<HttpHeader> httpHeader = proc->getHttpResponseHeader();
-  if(Util::toLower(httpHeader->getFirst("Connection")).find("close") != std::string::npos
-     || httpHeader->getVersion() != "HTTP/1.1") {
+  if(Util::toLower(httpHeader->getFirst(HttpHeader::CONNECTION)).find(HttpHeader::CLOSE) != std::string::npos
+     || httpHeader->getVersion() != HttpHeader::HTTP_1_1) {
     entry->getHttpRequest()->getRequest()->supportsPersistentConnection(false);
   } else {
     entry->getHttpRequest()->getRequest()->supportsPersistentConnection(true);

+ 20 - 0
src/HttpHeader.cc

@@ -40,6 +40,26 @@
 
 namespace aria2 {
 
+const std::string HttpHeader::LOCATION("Location");
+
+const std::string HttpHeader::TRANSFER_ENCODING("Transfer-Encoding");
+
+const std::string HttpHeader::CONTENT_DISPOSITION("Content-Disposition");
+
+const std::string HttpHeader::SET_COOKIE("Set-Cookie");
+
+const std::string HttpHeader::CHUNKED("chunked");
+
+const std::string HttpHeader::CONTENT_TYPE("Content-Type");
+
+const std::string HttpHeader::RETRY_AFTER("Retry-After");
+
+const std::string HttpHeader::CONNECTION("Connection");
+
+const std::string HttpHeader::CLOSE("close");
+
+const std::string HttpHeader::HTTP_1_1("HTTP/1.1");
+
 void HttpHeader::put(const std::string& name, const std::string& value) {
   std::multimap<std::string, std::string>::value_type vt(Util::toLower(name), value);
   table.insert(vt);

+ 20 - 0
src/HttpHeader.h

@@ -78,6 +78,26 @@ public:
   void setVersion(const std::string& version);
 
   void fill(std::istream& in);
+
+  static const std::string LOCATION;
+
+  static const std::string TRANSFER_ENCODING;
+  
+  static const std::string CONTENT_DISPOSITION;
+  
+  static const std::string SET_COOKIE;
+  
+  static const std::string CHUNKED;
+  
+  static const std::string CONTENT_TYPE;
+  
+  static const std::string RETRY_AFTER;
+  
+  static const std::string CONNECTION;
+
+  static const std::string CLOSE;
+
+  static const std::string HTTP_1_1;
 };
 
 typedef SharedHandle<HttpHeader> HttpHeaderHandle;

+ 13 - 12
src/HttpResponse.cc

@@ -64,13 +64,13 @@ void HttpResponse::validateResponse() const
     return;
   }
   if(status >= "300") {
-    if(!httpHeader->defined("Location")) {
+    if(!httpHeader->defined(HttpHeader::LOCATION)) {
       throw DlAbortEx
 	(StringFormat(EX_LOCATION_HEADER_REQUIRED,
 		      Util::parseUInt(status)).str());
     }
   } else {
-    if(!httpHeader->defined("Transfer-Encoding")) {
+    if(!httpHeader->defined(HttpHeader::TRANSFER_ENCODING)) {
       // compare the received range against the requested range
       RangeHandle responseRange = httpHeader->getRange();
       if(!httpRequest->isRangeSatisfied(responseRange)) {
@@ -91,7 +91,8 @@ void HttpResponse::validateResponse() const
 std::string HttpResponse::determinFilename() const
 {
   std::string contentDisposition =
-    Util::getContentDispositionFilename(httpHeader->getFirst("Content-Disposition"));
+    Util::getContentDispositionFilename
+    (httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION));
   if(contentDisposition.empty()) {
     return Util::urldecode(httpRequest->getFile());
   } else {
@@ -103,7 +104,7 @@ std::string HttpResponse::determinFilename() const
 
 void HttpResponse::retrieveCookie()
 {
-  std::deque<std::string> v = httpHeader->get("Set-Cookie");
+  std::deque<std::string> v = httpHeader->get(HttpHeader::SET_COOKIE);
   for(std::deque<std::string>::const_iterator itr = v.begin(); itr != v.end(); itr++) {
     std::string domain = httpRequest->getHost();
     std::string path = httpRequest->getDir();
@@ -114,7 +115,7 @@ void HttpResponse::retrieveCookie()
 bool HttpResponse::isRedirect() const
 {
   const std::string& status = getResponseStatus();
-  return "300" <= status && status < "400" && httpHeader->defined("Location");
+  return "300" <= status && status < "400" && httpHeader->defined(HttpHeader::LOCATION);
 }
 
 void HttpResponse::processRedirect()
@@ -125,23 +126,23 @@ void HttpResponse::processRedirect()
 
 std::string HttpResponse::getRedirectURI() const
 {
-  return httpHeader->getFirst("Location");
+  return httpHeader->getFirst(HttpHeader::LOCATION);
 }
 
 bool HttpResponse::isTransferEncodingSpecified() const
 {
-  return httpHeader->defined("Transfer-Encoding");
+  return httpHeader->defined(HttpHeader::TRANSFER_ENCODING);
 }
 
 std::string HttpResponse::getTransferEncoding() const
 {
-  return httpHeader->getFirst("Transfer-Encoding");
+  return httpHeader->getFirst(HttpHeader::TRANSFER_ENCODING);
 }
 
 TransferEncodingHandle HttpResponse::getTransferDecoder() const
 {
   if(isTransferEncodingSpecified()) {
-    if(getTransferEncoding() == "chunked") {
+    if(getTransferEncoding() == HttpHeader::CHUNKED) {
       return SharedHandle<TransferEncoding>(new ChunkedEncoding());
     }
   }
@@ -171,7 +172,7 @@ std::string HttpResponse::getContentType() const
   if(httpHeader.isNull()) {
     return A2STR::NIL;
   } else {
-    return httpHeader->getFirst("Content-Type");
+    return httpHeader->getFirst(HttpHeader::CONTENT_TYPE);
   }
 }
 
@@ -203,12 +204,12 @@ const std::string& HttpResponse::getResponseStatus() const
 
 bool HttpResponse::hasRetryAfter() const
 {
-  return httpHeader->defined("Retry-After");
+  return httpHeader->defined(HttpHeader::RETRY_AFTER);
 }
 
 time_t HttpResponse::getRetryAfter() const
 {
-  return httpHeader->getFirstAsUInt("Retry-After");
+  return httpHeader->getFirstAsUInt(HttpHeader::RETRY_AFTER);
 }
 
 } // namespace aria2