1 /* 2 * MultipartRelated.cpp 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 #include <core/http/MultipartRelated.hpp> 17 18 #include <iostream> 19 20 #define kBoundary "END_OF_PART"; 21 #define kSectionBoundary "--END_OF_PART" 22 #define kTerminatingBoundary "--END_OF_PART--" 23 #define kContentType "multipart/related; boundary=END_OF_PART" 24 25 namespace rstudio { 26 namespace core { 27 namespace http { 28 addPart(const std::string & contentType,const std::string & body)29void MultipartRelated::addPart(const std::string& contentType, 30 const std::string& body) 31 { 32 bodyStream_ << kSectionBoundary << std::endl; 33 bodyStream_ << "Content-Type: " << contentType << std::endl << std::endl; 34 bodyStream_ << body << std::endl; 35 } 36 terminate()37void MultipartRelated::terminate() 38 { 39 bodyStream_ << kTerminatingBoundary; 40 } 41 contentType() const42std::string MultipartRelated::contentType() const 43 { 44 return kContentType; 45 } 46 body() const47std::string MultipartRelated::body() const 48 { 49 return bodyStream_.str(); 50 } 51 52 } // namespace http 53 } // namespace core 54 } // namespace rstudio 55