From fac8e1d27352e2175a350817121a9f35000dd26e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 27 Nov 2007 12:45:29 +0000 Subject: [PATCH] 2007-11-27 Tatsuhiro Tsujikawa Set Content-Type to SingleFileDownloadContext when http response is received. * src/HttpResponseCommand.cc * src/HttpResponse.{h, cc} * test/HttpResponseTest.cc --- ChangeLog | 8 ++++++++ src/HttpResponse.cc | 9 +++++++++ src/HttpResponse.h | 2 ++ src/HttpResponseCommand.cc | 1 + test/HttpResponseTest.cc | 12 ++++++++++++ 5 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6fa7b539..961a3f57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-11-27 Tatsuhiro Tsujikawa + + Set Content-Type to SingleFileDownloadContext when http response is + received. + * src/HttpResponseCommand.cc + * src/HttpResponse.{h, cc} + * test/HttpResponseTest.cc + 2007-11-27 Tatsuhiro Tsujikawa Rewritten to add content-type support. diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index a6d5a7d5..c186dbd3 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -146,3 +146,12 @@ int64_t HttpResponse::getEntityLength() const return httpHeader->getRange()->getEntityLength(); } } + +string HttpResponse::getContentType() const +{ + if(httpHeader.isNull()) { + return ""; + } else { + return httpHeader->getFirst("Content-Type"); + } +} diff --git a/src/HttpResponse.h b/src/HttpResponse.h index ac7afc9f..91ae7e16 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -89,6 +89,8 @@ public: int64_t getEntityLength() const; + string getContentType() const; + void setHttpHeader(const HttpHeaderHandle& httpHeader) { this->httpHeader = httpHeader; diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index cc014bbc..c60f3999 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -91,6 +91,7 @@ bool HttpResponseCommand::executeInternal() SingleFileDownloadContextHandle dctx = _requestGroup->getDownloadContext(); dctx->setTotalLength(totalLength); dctx->setFilename(httpResponse->determinFilename()); + dctx->setContentType(httpResponse->getContentType()); _requestGroup->preDownloadProcessing(); if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) { throw new DownloadFailureException(EX_DUPLICATE_FILE_DOWNLOAD, diff --git a/test/HttpResponseTest.cc b/test/HttpResponseTest.cc index 946244c6..c71ca830 100644 --- a/test/HttpResponseTest.cc +++ b/test/HttpResponseTest.cc @@ -13,6 +13,7 @@ class HttpResponseTest : public CppUnit::TestFixture { CPPUNIT_TEST(testGetContentLength_contentLength); //CPPUNIT_TEST(testGetContentLength_range); CPPUNIT_TEST(testGetEntityLength); + CPPUNIT_TEST(testGetContentType); CPPUNIT_TEST(testDeterminFilename_without_ContentDisposition); CPPUNIT_TEST(testDeterminFilename_with_ContentDisposition_zero_length); CPPUNIT_TEST(testDeterminFilename_with_ContentDisposition); @@ -36,6 +37,7 @@ public: void testGetContentLength_null(); void testGetContentLength_contentLength(); void testGetEntityLength(); + void testGetContentType(); void testDeterminFilename_without_ContentDisposition(); void testDeterminFilename_with_ContentDisposition_zero_length(); void testDeterminFilename_with_ContentDisposition(); @@ -90,6 +92,16 @@ void HttpResponseTest::testGetEntityLength() } +void HttpResponseTest::testGetContentType() +{ + HttpResponse httpResponse; + HttpHeaderHandle httpHeader = new HttpHeader(); + httpHeader->put("content-type", "application/octet-stream"); + httpResponse.setHttpHeader(httpHeader); + CPPUNIT_ASSERT_EQUAL(string("application/octet-stream"), + httpResponse.getContentType()); +} + void HttpResponseTest::testDeterminFilename_without_ContentDisposition() { HttpResponse httpResponse;