瀏覽代碼

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
Tatsuhiro Tsujikawa 18 年之前
父節點
當前提交
fac8e1d273
共有 5 個文件被更改,包括 32 次插入0 次删除
  1. 8 0
      ChangeLog
  2. 9 0
      src/HttpResponse.cc
  3. 2 0
      src/HttpResponse.h
  4. 1 0
      src/HttpResponseCommand.cc
  5. 12 0
      test/HttpResponseTest.cc

+ 8 - 0
ChangeLog

@@ -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>
 
 	Rewritten to add content-type support.

+ 9 - 0
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");
+  }
+}

+ 2 - 0
src/HttpResponse.h

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

+ 1 - 0
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,

+ 12 - 0
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;