*/
#include "squid.h"
+#include "HttpBody.h"
#include "MemBuf.h"
-void
-httpBodyInit(HttpBody * body)
+HttpBody::HttpBody() : mb(new MemBuf)
+{}
+
+HttpBody::~HttpBody()
{
- body->mb = new MemBuf;
+ clear();
+ delete mb;
}
void
-httpBodyClean(HttpBody * body)
+HttpBody::clear()
{
- assert(body);
-
- if (!body->mb->isNull())
- body->mb->clean();
-
- delete body->mb;
-
- body->mb = NULL;
+ if(!mb->isNull())
+ mb->clean();
}
/* set body by absorbing mb */
void
-httpBodySet(HttpBody * body, MemBuf * mb)
+HttpBody::setMb(MemBuf * mb_)
{
- assert(body);
- assert(body->mb->isNull());
- delete body->mb;
- body->mb = mb; /* absorb */
+ clear();
+ delete mb;
+ /* note: protection against assign-to-self is not needed
+ * as MemBuf doesn't have a copy-constructor. If such a constructor
+ * is ever added, add such protection here.
+ */
+ mb = mb_; /* absorb */
}
void
-httpBodyPackInto(const HttpBody * body, Packer * p)
+HttpBody::packInto(Packer * p) const
{
- assert(body && p);
+ assert(p);
- if (body->mb->contentSize())
- packerAppend(p, body->mb->content(), body->mb->contentSize());
+ if (mb->contentSize())
+ packerAppend(p, mb->content(), mb->contentSize());
}
--- /dev/null
+/*
+ * SQUID Web Proxy Cache http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ * Squid is the result of efforts by numerous individuals from
+ * the Internet community; see the CONTRIBUTORS file for full
+ * details. Many organizations have provided support for Squid's
+ * development; see the SPONSORS file for full details. Squid is
+ * Copyrighted (C) 2001 by the Regents of the University of
+ * California; see the COPYRIGHT file for full details. Squid
+ * incorporates software developed and/or copyrighted by other
+ * sources; see the CREDITS file for full details.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ * Author: kinkie
+ *
+ */
+
+#ifndef HTTPBODY_H_
+#define HTTPBODY_H_
+
+#include "MemBuf.h"
+class Packer;
+
+/** Representation of a short predetermined message
+ *
+ * This class is useful to represent short HTTP messages, whose
+ * contents are known in advance, e.g. error messages
+ */
+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 *);
+ /** output the HttpBody contents into the supplied packer
+ *
+ * \note content is not cleared by the output operation
+ */
+ void packInto(Packer *) const;
+
+ /// clear the HttpBody content
+ void clear();
+
+ /// \return true if there is any content in the HttpBody
+ bool hasContent() const { return (mb->contentSize()>0); }
+
+ /// \return size of the HttpBody's message content
+ mb_size_t contentSize() const { return mb->contentSize(); }
+
+ /// \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;
+};
+
+
+#endif /* HTTPBODY_H_ */
#include "squid.h"
#include "SquidTime.h"
#include "Store.h"
+#include "HttpBody.h"
#include "HttpReply.h"
#include "HttpHdrContRange.h"
#include "HttpHdrCc.h"
void
HttpReply::init()
{
- httpBodyInit(&body);
hdrCacheInit();
httpStatusLineInit(&sline);
pstate = psReadyToParseStartLine;
// points to a pipe that is owned and initiated by another object.
body_pipe = NULL;
- httpBodyClean(&body);
+ body.clear();
hdrCacheClean();
header.clean();
httpStatusLineClean(&sline);
HttpReply::packInto(Packer * p)
{
packHeadersInto(p);
- httpBodyPackInto(&body, p);
+ body.packInto(p);
}
/* create memBuf, create mem-based packer, pack, destroy packer, return MemBuf */
#ifndef SQUID_HTTPREPLY_H
#define SQUID_HTTPREPLY_H
+#include "HttpBody.h"
#include "HttpMsg.h"
#include "HttpStatusLine.h"
HttpHeaderMask.h \
HttpHeaderRange.h \
HttpHeaderTools.cc \
+ HttpBody.h \
HttpBody.cc \
HttpControlMsg.h \
HttpMsg.cc \
cbdata.cc \
cbdata.h \
ETag.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHdrCc.h \
HttpHdrCc.cc \
HelperChildConfig.cc \
$(HTCPSOURCE) \
http.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHeader.cc \
HttpHeaderTools.cc \
event.cc \
fd.cc \
filemap.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHdrCc.h \
HttpHdrCc.cc \
hier_code.h \
$(HTCPSOURCE) \
http.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHeader.cc \
HttpHeaderTools.cc \
hier_code.h \
$(HTCPSOURCE) \
http.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHeader.cc \
HttpHeaderTools.cc \
hier_code.h \
$(HTCPSOURCE) \
http.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHdrCc.h \
HttpHdrCc.cc \
hier_code.h \
$(HTCPSOURCE) \
http.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHeader.cc \
HttpHeaderTools.cc \
tests/stub_helper.cc \
tests/stub_HelperChildConfig.cc \
tests/stub_http.cc \
+ HttpBody.h \
+ HttpBody.cc \
tests/stub_HttpReply.cc \
tests/stub_HttpRequest.cc \
tests/stub_libcomm.cc \
fd.cc \
disk.cc \
filemap.cc \
+ HttpBody.h \
HttpBody.cc \
HttpReply.cc \
HttpStatusLine.cc \
event.cc \
fd.cc \
filemap.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHdrCc.cc \
HttpHdrContRange.cc \
fd.cc \
disk.cc \
filemap.cc \
+ HttpBody.h \
HttpBody.cc \
HttpReply.cc \
HttpStatusLine.cc \
fd.cc \
disk.cc \
filemap.cc \
+ HttpBody.h \
HttpBody.cc \
HttpReply.cc \
HttpStatusLine.cc \
hier_code.h \
$(HTCPSOURCE) \
http.cc \
+ HttpBody.h \
HttpBody.cc \
HttpHdrCc.h \
HttpHdrCc.cc \
rep->header.putStr(HDR_CONTENT_LANGUAGE, "en");
}
- httpBodySet(&rep->body, content);
+ rep->body.setMb(content);
/* do not memBufClean() or delete the content, it was absorbed by httpBody */
}
err->err_msg = errormessage;
errormessage = NULL;
rep = err->BuildHttpReply();
- assert (rep->body.mb->contentSize() >= 0);
- size_t errorprogress = rep->body.mb->contentSize();
+ assert (rep->body.hasContent());
+ size_t errorprogress = rep->body.contentSize();
/* Tell esiSend where to start sending from */
outbound_offset = 0;
/* copy the membuf from the reply to outbound */
- while (errorprogress < (size_t)rep->body.mb->contentSize()) {
+ while (errorprogress < (size_t)rep->body.contentSize()) {
appendOutboundData(new ESISegment);
- errorprogress += outboundtail->append(rep->body.mb->content() + errorprogress, rep->body.mb->contentSize() - errorprogress);
+ errorprogress += outboundtail->append(rep->body.content() + errorprogress, rep->body.contentSize() - errorprogress);
}
/* the esiCode now thinks that the error is the outbound,
#include "HttpStatusCode.h"
SQUIDCEXTERN const char *httpStatusString(http_status status);
-/* Http Body */
-/* init/clean */
-SQUIDCEXTERN void httpBodyInit(HttpBody * body);
-SQUIDCEXTERN void httpBodyClean(HttpBody * body);
-/* get body ptr (always use this) */
-SQUIDCEXTERN const char *httpBodyPtr(const HttpBody * body);
-/* set body, does not clone mb so you should not reuse it */
-SQUIDCEXTERN void httpBodySet(HttpBody * body, MemBuf * mb);
-
-/* pack */
-SQUIDCEXTERN void httpBodyPackInto(const HttpBody * body, Packer * p);
-
/* Http Cache Control Header Field */
SQUIDCEXTERN void httpHdrCcInitModule(void);
SQUIDCEXTERN void httpHdrCcCleanModule(void);
rep->packHeadersInto(&p);
mem_obj->markEndOfReplyHeaders();
- httpBodyPackInto(&rep->body, &p);
+ rep->body.packInto(&p);
packerClean(&p);
}
unsigned long *file_map;
};
-/*
- * Note: HttpBody is used only for messages with a small content that is
- * known a priory (e.g., error messages).
- */
-
-class MemBuf;
-
-struct _HttpBody {
- /* private */
- MemBuf *mb;
-};
-
#include "SquidString.h"
/* http header extention field */
typedef struct _HttpHeaderStat HttpHeaderStat;
-typedef struct _HttpBody HttpBody;
-
typedef struct _domain_ping domain_ping;
typedef struct _domain_type domain_type;
rep->header.putStr(HDR_LOCATION, min_u->url);
}
- httpBodySet(&rep->body, mb);
+ rep->body.setMb(mb);
/* don't clean or delete mb; rep->body owns it now */
e->replaceHttpReply(rep);
e->complete();