# HG changeset patch # User Sebastien Jodogne # Date 1439302140 -7200 # Node ID c388502a066dc7de8d459618f1bb68c764accd04 # Parent f938f7779bcb7ac86439adca742b3efd5a55d78d testing FilesystemHttpSender diff -r f938f7779bcb -r c388502a066d Core/HttpServer/BufferHttpSender.h --- 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; diff -r f938f7779bcb -r c388502a066d Core/HttpServer/FilesystemHttpSender.cpp --- 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(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) diff -r f938f7779bcb -r c388502a066d Core/HttpServer/FilesystemHttpSender.h --- 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(); diff -r f938f7779bcb -r c388502a066d Core/HttpServer/HttpOutput.cpp --- 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(), diff -r f938f7779bcb -r c388502a066d Core/HttpServer/IHttpStreamAnswer.h --- 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; diff -r f938f7779bcb -r c388502a066d OrthancServer/ParsedDicomFile.cpp --- 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; diff -r f938f7779bcb -r c388502a066d OrthancServer/ServerContext.cpp --- 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 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(accessor_.GetStorageArea()); + + FilesystemHttpSender sender(a, attachment.GetUuid()); + sender.SetSourceCompression(attachment.GetCompressionType()); + sender.SetContentType(GetMimeType(content)); + sender.SetContentFilename(instancePublicId + ".dcm"); + output.AnswerStream(sender); +#endif } diff -r f938f7779bcb -r c388502a066d Resources/Orthanc.doxygen --- 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