@@ -323,21 +323,31 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
323323 content.append (type.data (), type.length ());
324324 }
325325 content.append (" \r\n\r\n " );
326- std::ifstream infile (utils::toNativePath (file.path ()),
327- std::ifstream::binary);
328- if (!infile)
326+
327+ if (file.data () && file.dataLength () > 0 )
329328 {
330- LOG_ERROR << file.path () << " not found" ;
329+ content.append ((const char *)file.data (),
330+ file.dataLength ());
331331 }
332332 else
333333 {
334- std::streambuf *pbuf = infile.rdbuf ();
335- std::streamsize filesize = pbuf->pubseekoff (0 , infile.end );
336- pbuf->pubseekoff (0 , infile.beg ); // rewind
337- std::string str;
338- str.resize (filesize);
339- pbuf->sgetn (&str[0 ], filesize);
340- content.append (std::move (str));
334+ std::ifstream infile (utils::toNativePath (file.path ()),
335+ std::ifstream::binary);
336+ if (!infile)
337+ {
338+ LOG_ERROR << file.path () << " not found" ;
339+ }
340+ else
341+ {
342+ std::streambuf *pbuf = infile.rdbuf ();
343+ std::streamsize filesize =
344+ pbuf->pubseekoff (0 , infile.end );
345+ pbuf->pubseekoff (0 , infile.beg ); // rewind
346+ std::string str;
347+ str.resize (filesize);
348+ pbuf->sgetn (&str[0 ], filesize);
349+ content.append (std::move (str));
350+ }
341351 }
342352 content.append (" \r\n " );
343353 }
0 commit comments