瀏覽代碼

Removed HttpHeader::findAs{LL}Int and unused HttpResponse::{has,get}RetryAfter

Tatsuhiro Tsujikawa 13 年之前
父節點
當前提交
8f2030da09
共有 7 個文件被更改,包括 9 次插入56 次删除
  1. 0 20
      src/HttpHeader.cc
  2. 0 2
      src/HttpHeader.h
  3. 0 10
      src/HttpResponse.cc
  4. 0 4
      src/HttpResponse.h
  5. 7 4
      src/HttpServer.cc
  6. 2 2
      test/HttpHeaderProcessorTest.cc
  7. 0 14
      test/HttpResponseTest.cc

+ 0 - 20
src/HttpHeader.cc

@@ -85,26 +85,6 @@ HttpHeader::equalRange(int hdKey) const
   return table_.equal_range(hdKey);
 }
 
-int32_t HttpHeader::findAsInt(int hdKey) const
-{
-  const std::string& value = find(hdKey);
-  if(value.empty()) {
-    return 0;
-  } else {
-    return util::parseInt(value);
-  }
-}
-
-int64_t HttpHeader::findAsLLInt(int hdKey) const
-{
-  const std::string& value = find(hdKey);
-  if(value.empty()) {
-    return 0;
-  } else {
-    return util::parseLLInt(value);
-  }
-}
-
 RangeHandle HttpHeader::getRange() const
 {
   const std::string& rangeStr = find(CONTENT_RANGE);

+ 0 - 2
src/HttpHeader.h

@@ -107,8 +107,6 @@ public:
   std::pair<std::multimap<int, std::string>::const_iterator,
             std::multimap<int, std::string>::const_iterator>
   equalRange(int hdKey) const;
-  int32_t findAsInt(int hdKey) const;
-  int64_t findAsLLInt(int hdKey) const;
 
   SharedHandle<Range> getRange() const;
 

+ 0 - 10
src/HttpResponse.cc

@@ -271,16 +271,6 @@ int HttpResponse::getStatusCode() const
   return httpHeader_->getStatusCode();
 }
 
-bool HttpResponse::hasRetryAfter() const
-{
-  return httpHeader_->defined(HttpHeader::RETRY_AFTER);
-}
-
-time_t HttpResponse::getRetryAfter() const
-{
-  return httpHeader_->findAsInt(HttpHeader::RETRY_AFTER);
-}
-
 Time HttpResponse::getLastModifiedTime() const
 {
   return Time::parseHTTPDate(httpHeader_->find(HttpHeader::LAST_MODIFIED));

+ 0 - 4
src/HttpResponse.h

@@ -124,10 +124,6 @@ public:
     cuid_ = cuid;
   }
 
-  bool hasRetryAfter() const;
-
-  time_t getRetryAfter() const;
-
   Time getLastModifiedTime() const;
 
   bool supportsPersistentConnection() const;

+ 7 - 4
src/HttpServer.cc

@@ -148,10 +148,13 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
     if(setupResponseRecv() < 0) {
       A2_LOG_INFO("Request path is invaild. Ignore the request body.");
     }
-    lastContentLength_ =
-      lastRequestHeader_->findAsLLInt(HttpHeader::CONTENT_LENGTH);
-    if(lastContentLength_ < 0) {
-      throw DL_ABORT_EX("Content-Length must be positive.");
+    if(!util::parseLLIntNoThrow(lastContentLength_,
+                                lastRequestHeader_->
+                                find(HttpHeader::CONTENT_LENGTH)) ||
+       lastContentLength_ < 0) {
+      throw DL_ABORT_EX(fmt("Invalid Content-Length=%s",
+                            lastRequestHeader_->
+                            find(HttpHeader::CONTENT_LENGTH).c_str()));
     }
     headerProcessor_->clear();
 

+ 2 - 2
test/HttpHeaderProcessorTest.cc

@@ -140,8 +140,8 @@ void HttpHeaderProcessorTest::testGetHttpResponseHeader()
   CPPUNIT_ASSERT_EQUAL(404, header->getStatusCode());
   CPPUNIT_ASSERT_EQUAL(std::string("Not Found"), header->getReasonPhrase());
   CPPUNIT_ASSERT_EQUAL(std::string("HTTP/1.1"), header->getVersion());
-  CPPUNIT_ASSERT_EQUAL((int64_t)9187LL,
-                       header->findAsLLInt(HttpHeader::CONTENT_LENGTH));
+  CPPUNIT_ASSERT_EQUAL(std::string("9187"),
+                       header->find(HttpHeader::CONTENT_LENGTH));
   CPPUNIT_ASSERT_EQUAL(std::string("text/html; charset=UTF-8"),
                        header->find(HttpHeader::CONTENT_TYPE));
   CPPUNIT_ASSERT(!header->defined(HttpHeader::CONTENT_ENCODING));

+ 0 - 14
test/HttpResponseTest.cc

@@ -48,7 +48,6 @@ class HttpResponseTest : public CppUnit::TestFixture {
   CPPUNIT_TEST(testValidateResponse_bad_range);
   CPPUNIT_TEST(testValidateResponse_chunked);
   CPPUNIT_TEST(testValidateResponse_withIfModifiedSince);
-  CPPUNIT_TEST(testHasRetryAfter);
   CPPUNIT_TEST(testProcessRedirect);
   CPPUNIT_TEST(testRetrieveCookie);
   CPPUNIT_TEST(testSupportsPersistentConnection);
@@ -84,7 +83,6 @@ public:
   void testValidateResponse_bad_range();
   void testValidateResponse_chunked();
   void testValidateResponse_withIfModifiedSince();
-  void testHasRetryAfter();
   void testProcessRedirect();
   void testRetrieveCookie();
   void testSupportsPersistentConnection();
@@ -468,18 +466,6 @@ void HttpResponseTest::testValidateResponse_withIfModifiedSince()
   httpResponse.validateResponse();
 }
 
-void HttpResponseTest::testHasRetryAfter()
-{
-  HttpResponse httpResponse;
-  SharedHandle<HttpHeader> httpHeader(new HttpHeader());
-  httpResponse.setHttpHeader(httpHeader);
-
-  httpHeader->put(HttpHeader::RETRY_AFTER, "60");
-
-  CPPUNIT_ASSERT(httpResponse.hasRetryAfter());
-  CPPUNIT_ASSERT_EQUAL((time_t)60, httpResponse.getRetryAfter());
-}
-
 void HttpResponseTest::testProcessRedirect()
 {
   HttpResponse httpResponse;