diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index d72ca965a..40181bd37 100644 --- a/src/HttpHeader.cc +++ b/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); diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 25f385a0f..782a7d275 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -107,8 +107,6 @@ public: std::pair::const_iterator, std::multimap::const_iterator> equalRange(int hdKey) const; - int32_t findAsInt(int hdKey) const; - int64_t findAsLLInt(int hdKey) const; SharedHandle getRange() const; diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 182de9e3d..26272ee26 100644 --- a/src/HttpResponse.cc +++ b/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)); diff --git a/src/HttpResponse.h b/src/HttpResponse.h index 50f9f2e4c..ec2868284 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -124,10 +124,6 @@ public: cuid_ = cuid; } - bool hasRetryAfter() const; - - time_t getRetryAfter() const; - Time getLastModifiedTime() const; bool supportsPersistentConnection() const; diff --git a/src/HttpServer.cc b/src/HttpServer.cc index b7f467b1e..afb1ab45d 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -148,10 +148,13 @@ SharedHandle 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(); diff --git a/test/HttpHeaderProcessorTest.cc b/test/HttpHeaderProcessorTest.cc index c87ba4ed9..e9f7b3899 100644 --- a/test/HttpHeaderProcessorTest.cc +++ b/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)); diff --git a/test/HttpResponseTest.cc b/test/HttpResponseTest.cc index 9ed6f1800..49a59b282 100644 --- a/test/HttpResponseTest.cc +++ b/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(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;