]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/HttpBody.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / HttpBody.h
index 69df6450f12840795733145b7184ce40048ad4ec..1023c316e637cbf9456aceb17d1c39194b9b7a41 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -9,7 +9,9 @@
 #ifndef HTTPBODY_H_
 #define HTTPBODY_H_
 
-#include "MemBuf.h"
+#include "sbuf/SBuf.h"
+
+class Packable; // TODO: Add and use base/forward.h.
 
 /** Representation of a short predetermined message
  *
 class HttpBody
 {
 public:
-    HttpBody();
-    ~HttpBody();
-    /** absorb the MemBuf, discarding anything currently stored
-     *
-     * After this call the lifetime of the passed MemBuf is managed
-     * by the HttpBody.
-     */
-    void setMb(MemBuf *);
+    HttpBody() {}
+
+    void set(const SBuf &newContent) { raw_ = newContent; }
 
     /** output the HttpBody contents into the supplied container
      *
@@ -35,20 +32,22 @@ public:
     void packInto(Packable *) const;
 
     /// clear the HttpBody content
-    void clear();
+    void clear() { raw_.clear(); }
 
     /// \return true if there is any content in the HttpBody
-    bool hasContent() const { return (mb->contentSize()>0); }
+    bool hasContent() const { return raw_.length() > 0; }
 
     /// \return size of the HttpBody's message content
-    mb_size_t contentSize() const { return mb->contentSize(); }
+    size_t contentSize() const { return raw_.length(); }
+
+    /// \return body bytes (possibly not nil-terminated)
+    const char *content() const { return raw_.rawContent(); }
 
-    /// \return pointer to the storage of the HttpBody
-    char *content() const { return mb->content(); }
 private:
     HttpBody& operator=(const HttpBody&); //not implemented
     HttpBody(const HttpBody&); // not implemented
-    MemBuf *mb;
+
+    SBuf raw_; // body bytes
 };
 
 #endif /* HTTPBODY_H_ */