1 /* 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors 3 * 4 * Squid software is distributed under GPLv2+ license and includes 5 * contributions from numerous individuals and organizations. 6 * Please see the COPYING and CONTRIBUTORS files for details. 7 */ 8 9 #ifndef HTTPBODY_H_ 10 #define HTTPBODY_H_ 11 12 #include "MemBuf.h" 13 14 /** Representation of a short predetermined message 15 * 16 * This class is useful to represent short HTTP messages, whose 17 * contents are known in advance, e.g. error messages 18 */ 19 class HttpBody 20 { 21 public: 22 HttpBody(); 23 ~HttpBody(); 24 /** absorb the MemBuf, discarding anything currently stored 25 * 26 * After this call the lifetime of the passed MemBuf is managed 27 * by the HttpBody. 28 */ 29 void setMb(MemBuf *); 30 31 /** output the HttpBody contents into the supplied container 32 * 33 * \note content is not cleared by the output operation 34 */ 35 void packInto(Packable *) const; 36 37 /// clear the HttpBody content 38 void clear(); 39 40 /// \return true if there is any content in the HttpBody hasContent()41 bool hasContent() const { return (mb->contentSize()>0); } 42 43 /// \return size of the HttpBody's message content contentSize()44 mb_size_t contentSize() const { return mb->contentSize(); } 45 46 /// \return pointer to the storage of the HttpBody content()47 char *content() const { return mb->content(); } 48 private: 49 HttpBody& operator=(const HttpBody&); //not implemented 50 HttpBody(const HttpBody&); // not implemented 51 MemBuf *mb; 52 }; 53 54 #endif /* HTTPBODY_H_ */ 55 56