Re: [Cppcms-users] HTTP response and binary stream (libharu)
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2015-09-18 19:22:24
|
Several points: (a) You misunderstand meaning of "raw" output - "raw" means you are sending CGI output including headers etc on your own and CppCMS does not interfere with it. There only very-very specific cases you may actually need this - bottom line you don't need it.(b) std::ostream is just a character or more correctly octet stream, std::string is a container that keeps bytes/"C chars"/octets in it in string friendly way. You can put any binary data to it. Now in your case the problem is there" app()->response().out() << buf << std::flush; or cppcms_buf << buf Why? std::ostream assumes that buf is NUL terminated string so it would stop on NUL, and this what corrupts the stream.You need to use std::ostream::write, i.e. out().write(buf,siz) That's it Artyom Beilis From: augustin <aug...@ov...> To: cpp...@li... Sent: Thursday, September 17, 2015 4:16 PM Subject: Re: [Cppcms-users] HTTP response and binary stream (libharu) On Thursday, September 17, 2015 07:07:21 PM Joerg Sonnenberger wrote: > On Thu, Sep 17, 2015 at 05:52:03PM +0800, augustin wrote: > > I am trying to get my cppcms application to output a PDF file (using > > libharu). However, I seem to have a problem returning the binary output. > > It seems that the cppcms internals are corrupting the stream. > > Works fine for me, but I don't set raw mode or anything like that, just: > > response().content_type("application/pdf"); > response().out() << pdf; > > where pdf is a std::string. Thanks, but pdf is not a std::string. It is a HPDF_Doc from the libharu library, which is used to create documents following the PDF standard. A PDF file may include binary streams. I have no problem outputting HTML (std::string). I have no problem outputting simple PDF files which only include a stream of strings. But when I try creating more complex PDF files with drawings or pictures (i.e. PDF files including binary streams), the file gets corrupted and is not rendered properly. Right now, I am learning about the complexities of having binary streams in C++. There are quite a few articles on the topic on the internet. My main question is: is it a problem in my own code, or is it a shortcoming of the cppcms library, that it cannot handle binary streams? Does cppcms need to be patched or should I handle the stream differently on my end? thanks, augustin. ------------------------------------------------------------------------------ Monitor Your Dynamic Infrastructure at Any Scale With Datadog! Get real-time metrics from all of your servers, apps and tools in one place. SourceForge users - Click here to start your Free Trial of Datadog now! http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140 _______________________________________________ Cppcms-users mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppcms-users |