/*
- * Copyright (C) 1996-2018 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.
#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
*
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_ */