2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Set Content-Type to SingleFileDownloadContext when http response 
is
	received.
	* src/HttpResponseCommand.cc
	* src/HttpResponse.{h, cc}
	* test/HttpResponseTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2007-11-27 12:45:29 +00:00
parent 506bc3db13
commit fac8e1d273
5 changed files with 32 additions and 0 deletions

View File

@ -1,3 +1,11 @@
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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 <tujikawa at rednoah dot com> 2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support. Rewritten to add content-type support.

View File

@ -146,3 +146,12 @@ int64_t HttpResponse::getEntityLength() const
return httpHeader->getRange()->getEntityLength(); return httpHeader->getRange()->getEntityLength();
} }
} }
string HttpResponse::getContentType() const
{
if(httpHeader.isNull()) {
return "";
} else {
return httpHeader->getFirst("Content-Type");
}
}

View File

@ -89,6 +89,8 @@ public:
int64_t getEntityLength() const; int64_t getEntityLength() const;
string getContentType() const;
void setHttpHeader(const HttpHeaderHandle& httpHeader) void setHttpHeader(const HttpHeaderHandle& httpHeader)
{ {
this->httpHeader = httpHeader; this->httpHeader = httpHeader;

View File

@ -91,6 +91,7 @@ bool HttpResponseCommand::executeInternal()
SingleFileDownloadContextHandle dctx = _requestGroup->getDownloadContext(); SingleFileDownloadContextHandle dctx = _requestGroup->getDownloadContext();
dctx->setTotalLength(totalLength); dctx->setTotalLength(totalLength);
dctx->setFilename(httpResponse->determinFilename()); dctx->setFilename(httpResponse->determinFilename());
dctx->setContentType(httpResponse->getContentType());
_requestGroup->preDownloadProcessing(); _requestGroup->preDownloadProcessing();
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) { if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
throw new DownloadFailureException(EX_DUPLICATE_FILE_DOWNLOAD, throw new DownloadFailureException(EX_DUPLICATE_FILE_DOWNLOAD,

View File

@ -13,6 +13,7 @@ class HttpResponseTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testGetContentLength_contentLength); CPPUNIT_TEST(testGetContentLength_contentLength);
//CPPUNIT_TEST(testGetContentLength_range); //CPPUNIT_TEST(testGetContentLength_range);
CPPUNIT_TEST(testGetEntityLength); CPPUNIT_TEST(testGetEntityLength);
CPPUNIT_TEST(testGetContentType);
CPPUNIT_TEST(testDeterminFilename_without_ContentDisposition); CPPUNIT_TEST(testDeterminFilename_without_ContentDisposition);
CPPUNIT_TEST(testDeterminFilename_with_ContentDisposition_zero_length); CPPUNIT_TEST(testDeterminFilename_with_ContentDisposition_zero_length);
CPPUNIT_TEST(testDeterminFilename_with_ContentDisposition); CPPUNIT_TEST(testDeterminFilename_with_ContentDisposition);
@ -36,6 +37,7 @@ public:
void testGetContentLength_null(); void testGetContentLength_null();
void testGetContentLength_contentLength(); void testGetContentLength_contentLength();
void testGetEntityLength(); void testGetEntityLength();
void testGetContentType();
void testDeterminFilename_without_ContentDisposition(); void testDeterminFilename_without_ContentDisposition();
void testDeterminFilename_with_ContentDisposition_zero_length(); void testDeterminFilename_with_ContentDisposition_zero_length();
void testDeterminFilename_with_ContentDisposition(); 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() void HttpResponseTest::testDeterminFilename_without_ContentDisposition()
{ {
HttpResponse httpResponse; HttpResponse httpResponse;