changeset 1523:c388502a066d

testing FilesystemHttpSender
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2015 16:09:00 +0200
parents f938f7779bcb
children 4a0c2eedceb6
files Core/HttpServer/BufferHttpSender.h Core/HttpServer/FilesystemHttpSender.cpp Core/HttpServer/FilesystemHttpSender.h Core/HttpServer/HttpOutput.cpp Core/HttpServer/IHttpStreamAnswer.h OrthancServer/ParsedDicomFile.cpp OrthancServer/ServerContext.cpp Resources/Orthanc.doxygen
diffstat 8 files changed, 60 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/BufferHttpSender.h	Tue Aug 11 15:37:42 2015 +0200
+++ b/Core/HttpServer/BufferHttpSender.h	Tue Aug 11 16:09:00 2015 +0200
@@ -61,8 +61,8 @@
      * Implementation of the IHttpStreamAnswer interface.
      **/
 
-    virtual HttpCompression GetHttpCompression(bool /*gzipAllowed*/, 
-                                               bool /*deflateAllowed*/)
+    virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/, 
+                                                 bool /*deflateAllowed*/)
     {
       // No compression is supported
       return HttpCompression_None;
--- a/Core/HttpServer/FilesystemHttpSender.cpp	Tue Aug 11 15:37:42 2015 +0200
+++ b/Core/HttpServer/FilesystemHttpSender.cpp	Tue Aug 11 16:09:00 2015 +0200
@@ -62,8 +62,8 @@
   }
 
 
-  HttpCompression FilesystemHttpSender::GetHttpCompression(bool gzipAllowed, 
-                                                           bool deflateAllowed)
+  HttpCompression FilesystemHttpSender::SetupHttpCompression(bool gzipAllowed, 
+                                                             bool deflateAllowed)
   {
     switch (sourceCompression_)
     {
@@ -86,7 +86,8 @@
 
         if (deflateAllowed)
         {
-          file_.seekg(sizeof(uint64_t), file_.end);
+          file_.seekg(sizeof(uint64_t), file_.beg);
+          size_ -= sizeof(uint64_t);
           return HttpCompression_Deflate;
         }
         else
@@ -100,13 +101,16 @@
 
           file_.read(&compressed[0], size_);
           if ((file_.flags() & std::istream::failbit) ||
-              !(file_.flags() & std::istream::eofbit))
+              !(file_.flags() & std::istream::eofbit) ||
+              file_.gcount() < 0 ||
+              static_cast<uint64_t>(file_.gcount()) != size_)
           {
             throw OrthancException(ErrorCode_CorruptedFile);
           }
           
           ZlibCompressor compressor;
           IBufferCompressor::Uncompress(uncompressed_->GetBuffer(), compressor, compressed);
+
           return HttpCompression_None;
         }
 
@@ -119,6 +123,19 @@
   }
 
 
+  uint64_t FilesystemHttpSender::GetContentLength()
+  {
+    if (uncompressed_.get() != NULL)
+    {
+      return uncompressed_->GetContentLength();
+    }
+    else
+    {
+      return size_;
+    }
+  }
+
+
   bool FilesystemHttpSender::ReadNextChunk()
   {
     if (uncompressed_.get() != NULL)
--- a/Core/HttpServer/FilesystemHttpSender.h	Tue Aug 11 15:37:42 2015 +0200
+++ b/Core/HttpServer/FilesystemHttpSender.h	Tue Aug 11 16:09:00 2015 +0200
@@ -80,13 +80,10 @@
      * Implementation of the IHttpStreamAnswer interface.
      **/
 
-    virtual HttpCompression GetHttpCompression(bool /*gzipAllowed*/, 
-                                               bool /*deflateAllowed*/);
+    virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/, 
+                                                 bool /*deflateAllowed*/);
 
-    virtual uint64_t GetContentLength()
-    {
-      return size_;
-    }
+    virtual uint64_t GetContentLength();
 
     virtual bool ReadNextChunk();
 
--- a/Core/HttpServer/HttpOutput.cpp	Tue Aug 11 15:37:42 2015 +0200
+++ b/Core/HttpServer/HttpOutput.cpp	Tue Aug 11 16:09:00 2015 +0200
@@ -502,23 +502,7 @@
 
   void HttpOutput::Answer(IHttpStreamAnswer& stream)
   {
-    stateMachine_.SetContentLength(stream.GetContentLength());
-
-    std::string contentType = stream.GetContentType();
-    if (contentType.empty())
-    {
-      contentType = "application/octet-stream";
-    }
-
-    stateMachine_.SetContentType(contentType.c_str());
-
-    std::string filename;
-    if (stream.HasContentFilename(filename))
-    {
-      SetContentFilename(filename.c_str());
-    }
-
-    HttpCompression compression = stream.GetHttpCompression(isGzipAllowed_, isDeflateAllowed_);
+    HttpCompression compression = stream.SetupHttpCompression(isGzipAllowed_, isDeflateAllowed_);
 
     switch (compression)
     {
@@ -537,6 +521,22 @@
         throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
 
+    stateMachine_.SetContentLength(stream.GetContentLength());
+
+    std::string contentType = stream.GetContentType();
+    if (contentType.empty())
+    {
+      contentType = "application/octet-stream";
+    }
+
+    stateMachine_.SetContentType(contentType.c_str());
+
+    std::string filename;
+    if (stream.HasContentFilename(filename))
+    {
+      SetContentFilename(filename.c_str());
+    }
+
     while (stream.ReadNextChunk())
     {
       stateMachine_.SendBody(stream.GetChunkContent(),
--- a/Core/HttpServer/IHttpStreamAnswer.h	Tue Aug 11 15:37:42 2015 +0200
+++ b/Core/HttpServer/IHttpStreamAnswer.h	Tue Aug 11 16:09:00 2015 +0200
@@ -44,8 +44,9 @@
     {
     }
 
-    virtual HttpCompression GetHttpCompression(bool gzipAllowed,
-                                               bool deflateAllowed) = 0;
+    // This is the first method to be called
+    virtual HttpCompression SetupHttpCompression(bool gzipAllowed,
+                                                 bool deflateAllowed) = 0;
 
     virtual bool HasContentFilename(std::string& filename) = 0;
 
--- a/OrthancServer/ParsedDicomFile.cpp	Tue Aug 11 15:37:42 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Tue Aug 11 16:09:00 2015 +0200
@@ -277,8 +277,8 @@
         chunk_.resize(CHUNK_SIZE);
       }
 
-      virtual HttpCompression GetHttpCompression(bool /*gzipAllowed*/,
-                                                 bool /*deflateAllowed*/)
+      virtual HttpCompression SetupHttpCompression(bool /*gzipAllowed*/,
+                                                   bool /*deflateAllowed*/)
       {
         // No support for compression
         return HttpCompression_None;
--- a/OrthancServer/ServerContext.cpp	Tue Aug 11 15:37:42 2015 +0200
+++ b/OrthancServer/ServerContext.cpp	Tue Aug 11 16:09:00 2015 +0200
@@ -313,12 +313,22 @@
       throw OrthancException(ErrorCode_InternalError);
     }
 
+#if 1
     accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
 
     std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid(), attachment.GetContentType()));
     sender->SetContentType(GetMimeType(content));
-    sender->SetContentFilename(instancePublicId + ".dcm");
+    sender->SetContentFilename(instancePublicId + ".dcm");  // TODO ".dcm" => ToMimeType(content)
     output.AnswerStream(*sender);
+#else
+    const FilesystemStorage& a = dynamic_cast<FilesystemStorage&>(accessor_.GetStorageArea());
+    
+    FilesystemHttpSender sender(a, attachment.GetUuid());
+    sender.SetSourceCompression(attachment.GetCompressionType());
+    sender.SetContentType(GetMimeType(content));
+    sender.SetContentFilename(instancePublicId + ".dcm");
+    output.AnswerStream(sender);
+#endif
   }
 
 
--- a/Resources/Orthanc.doxygen	Tue Aug 11 15:37:42 2015 +0200
+++ b/Resources/Orthanc.doxygen	Tue Aug 11 16:09:00 2015 +0200
@@ -1600,7 +1600,7 @@
 # toolkit from AT&T and Lucent Bell Labs. The other options in this section
 # have no effect if this option is set to NO (the default)
 
-HAVE_DOT               = NO
+HAVE_DOT               = YES
 
 # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
 # allowed to run in parallel. When set to 0 (the default) doxygen will