]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpBody.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / HttpBody.h
1 /*
2 * Copyright (C) 1996-2020 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 "sbuf/SBuf.h"
13
14 class Packable; // TODO: Add and use base/forward.h.
15
16 /** Representation of a short predetermined message
17 *
18 * This class is useful to represent short HTTP messages, whose
19 * contents are known in advance, e.g. error messages
20 */
21 class HttpBody
22 {
23 public:
24 HttpBody() {}
25
26 void set(const SBuf &newContent) { raw_ = newContent; }
27
28 /** output the HttpBody contents into the supplied container
29 *
30 * \note content is not cleared by the output operation
31 */
32 void packInto(Packable *) const;
33
34 /// clear the HttpBody content
35 void clear() { raw_.clear(); }
36
37 /// \return true if there is any content in the HttpBody
38 bool hasContent() const { return raw_.length() > 0; }
39
40 /// \return size of the HttpBody's message content
41 size_t contentSize() const { return raw_.length(); }
42
43 /// \return body bytes (possibly not nil-terminated)
44 const char *content() const { return raw_.rawContent(); }
45
46 private:
47 HttpBody& operator=(const HttpBody&); //not implemented
48 HttpBody(const HttpBody&); // not implemented
49
50 SBuf raw_; // body bytes
51 };
52
53 #endif /* HTTPBODY_H_ */
54