/*
- * $Id: HttpMsg.cc,v 1.15 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpMsg.cc,v 1.16 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 74 HTTP Message
* AUTHOR: Alex Rousskov
if (!httpHeaderParse(&header, blk_start, blk_end))
return httpMsgParseError();
- if (rep)
- httpReplyHdrCacheInit(rep);
- else if (req)
- httpRequestHdrCacheInit(req);
+ hdrCacheInit();
*parse_end_ptr = parse_start;
packerAppend(p, "\r\n", 2);
}
-
+void HttpMsg::hdrCacheInit()
+{
+ content_length = httpHeaderGetInt(&header, HDR_CONTENT_LENGTH);
+ assert(NULL == cache_control);
+ cache_control = httpHeaderGetCc(&header);
+}
/*
- * $Id: HttpMsg.h,v 1.1 2005/09/13 17:45:05 wessels Exp $
+ * $Id: HttpMsg.h,v 1.2 2005/09/15 19:22:30 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
protected:
virtual void packFirstLineInto(Packer * p, bool full_uri) const = 0;
+ virtual void hdrCacheInit();
};
/*
- * $Id: HttpReply.cc,v 1.73 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpReply.cc,v 1.74 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 58 HTTP Reply (Response)
* AUTHOR: Alex Rousskov
HttpReply::HttpReply() : HttpMsg(hoReply), date (0), last_modified (0), expires (0), surrogate_control (NULL), content_range (NULL), keep_alive (0), protoPrefix("HTTP/")
{
httpBodyInit(&body);
- httpReplyHdrCacheInit(this);
+ hdrCacheInit();
httpStatusLineInit(&sline);
}
*rep = *new_rep;
new_rep->header.entries.clean();
/* cannot use Clean() on new reply now! */
+ new_rep->cache_control = NULL; // helps with debugging
httpReplyDoDestroy(new_rep);
}
void
-httpReplyUpdateOnNotModified(HttpReply * rep, HttpReply const * freshRep)
+HttpReply::httpReplyUpdateOnNotModified(HttpReply const * freshRep)
{
- assert(rep && freshRep);
+ assert(freshRep);
/* Can not update modified headers that don't match! */
- assert (httpReplyValidatorsMatch(rep, freshRep));
+ assert (httpReplyValidatorsMatch(this, freshRep));
/* clean cache */
- httpReplyHdrCacheClean(rep);
+ httpReplyHdrCacheClean(this);
/* update raw headers */
- httpHeaderUpdate(&rep->header, &freshRep->header,
+ httpHeaderUpdate(&header, &freshRep->header,
(const HttpHeaderMask *) &Denied304HeadersMask);
/* init cache */
- httpReplyHdrCacheInit(rep);
+ hdrCacheInit();
}
/* sync this routine when you update HttpReply struct */
void
-httpReplyHdrCacheInit(HttpReply * rep)
+HttpReply::hdrCacheInit()
{
- const HttpHeader *hdr = &rep->header;
- const char *str;
- rep->content_length = httpHeaderGetInt(hdr, HDR_CONTENT_LENGTH);
- rep->date = httpHeaderGetTime(hdr, HDR_DATE);
- rep->last_modified = httpHeaderGetTime(hdr, HDR_LAST_MODIFIED);
- str = httpHeaderGetStr(hdr, HDR_CONTENT_TYPE);
+ HttpMsg::hdrCacheInit();
+
+ content_length = httpHeaderGetInt(&header, HDR_CONTENT_LENGTH);
+ date = httpHeaderGetTime(&header, HDR_DATE);
+ last_modified = httpHeaderGetTime(&header, HDR_LAST_MODIFIED);
+ surrogate_control = httpHeaderGetSc(&header);
+ content_range = httpHeaderGetContRange(&header);
+ keep_alive = httpMsgIsPersistent(sline.version, &header);
+ const char *str = httpHeaderGetStr(&header, HDR_CONTENT_TYPE);
if (str)
- rep->content_type.limitInit(str, strcspn(str, ";\t "));
+ content_type.limitInit(str, strcspn(str, ";\t "));
else
- rep->content_type = String();
-
- rep->cache_control = httpHeaderGetCc(hdr);
-
- rep->surrogate_control = httpHeaderGetSc(hdr);
-
- rep->content_range = httpHeaderGetContRange(hdr);
-
- rep->keep_alive = httpMsgIsPersistent(rep->sline.version, &rep->header);
+ content_type = String();
/* be sure to set expires after date and cache-control */
- rep->expires = httpReplyHdrExpirationTime(rep);
+ expires = httpReplyHdrExpirationTime(this);
}
/* sync this routine when you update HttpReply struct */
{
rep->content_type.clean();
- if (rep->cache_control)
+ if (rep->cache_control) {
httpHdrCcDestroy(rep->cache_control);
+ rep->cache_control = NULL;
+ }
- if (rep->surrogate_control)
+ if (rep->surrogate_control) {
httpHdrScDestroy(rep->surrogate_control);
+ rep->surrogate_control = NULL;
+ }
- if (rep->content_range)
+ if (rep->content_range) {
httpHdrContRangeDestroy(rep->content_range);
+ rep->content_range = NULL;
+ }
}
/*
/*
- * $Id: HttpReply.h,v 1.9 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpReply.h,v 1.10 2005/09/15 19:22:30 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
extern MemBuf *httpPacked304Reply(const HttpReply * rep);
/* construct a 304 reply and return it */
extern HttpReply *httpReplyMake304(const HttpReply *rep);
-/* update when 304 reply is received for a cached object */
-extern void httpReplyUpdateOnNotModified(HttpReply * rep, HttpReply const * freshRep);
/* header manipulation */
extern int httpReplyContentLen(const HttpReply * rep);
extern const char *httpReplyContentType(const HttpReply * rep);
extern void httpRedirectReply(HttpReply *, http_status, const char *);
extern int httpReplyBodySize(method_t, HttpReply const *);
extern int httpReplyValidatorsMatch (HttpReply const *, HttpReply const *);
-extern void httpReplyHdrCacheInit(HttpReply * rep);
/* Sync changes here with HttpReply.cc */
String protoPrefix; // e.g., "HTTP/"
+public:
+ void httpReplyUpdateOnNotModified(HttpReply const *other);
+
protected:
virtual void packFirstLineInto(Packer * p, bool) const;
+ virtual void hdrCacheInit();
};
MEMPROXY_CLASS_INLINE(HttpReply)
/*
- * $Id: HttpRequest.cc,v 1.49 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpRequest.cc,v 1.50 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 73 HTTP Request
* AUTHOR: Duane Wessels
req->my_addr = no_addr;
- httpRequestHdrCacheInit(req);
-
return req;
}
httpHeaderClean(&header);
- if (cache_control)
+ if (cache_control) {
httpHdrCcDestroy(cache_control);
+ cache_control = NULL;
+ }
if (range)
delete range;
}
int
-httpRequestParseHeader(HttpRequest * req, const char *parse_start)
+HttpRequest::parseHeader(const char *parse_start)
{
const char *blk_start, *blk_end;
if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end))
return 0;
- int result = httpHeaderParse(&req->header, blk_start, blk_end);
+ int result = httpHeaderParse(&header, blk_start, blk_end);
if (result)
- httpRequestHdrCacheInit(req);
+ hdrCacheInit();
return result;
}
/* sync this routine when you update HttpRequest struct */
void
-httpRequestHdrCacheInit(HttpRequest * req)
+HttpRequest::hdrCacheInit()
{
- const HttpHeader *hdr = &req->header;
- /* const char *str; */
- req->content_length = httpHeaderGetInt(hdr, HDR_CONTENT_LENGTH);
- /* TODO: canonicalise these into an HttpEntity */
-#if 0
-
- req->date = httpHeaderGetTime(hdr, HDR_DATE);
- req->last_modified = httpHeaderGetTime(hdr, HDR_LAST_MODIFIED);
- str = httpHeaderGetStr(hdr, HDR_CONTENT_TYPE);
-
- if (str)
- stringLimitInit(&req->content_type, str, strcspn(str, ";\t "));
- else
- req->content_type = String();
-
-#endif
+ HttpMsg::hdrCacheInit();
- req->cache_control = httpHeaderGetCc(hdr);
-
- req->range = httpHeaderGetRange(hdr);
-
-#if 0
-
- req->keep_alive = httpMsgIsPersistent(req->http_ver, &req->header);
-
- /* be sure to set expires after date and cache-control */
- req->expires = httpReplyHdrExpirationTime(req);
-
-#endif
+ range = httpHeaderGetRange(&header);
}
/* request_flags */
/*
- * $Id: HttpRequest.h,v 1.12 2005/09/12 23:28:57 wessels Exp $
+ * $Id: HttpRequest.h,v 1.13 2005/09/15 19:22:30 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
extern void requestDestroy(HttpRequest *);
extern HttpRequest *requestLink(HttpRequest *);
extern void requestUnlink(HttpRequest *);
-extern int httpRequestParseHeader(HttpRequest * req, const char *parse_start);
extern void httpRequestSwapOut(const HttpRequest * req, StoreEntry * e);
extern void httpRequestPack(const HttpRequest * req, Packer * p);
extern int httpRequestPrefixLen(const HttpRequest * req);
extern int httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConnection);
extern int httpRequestHdrAllowedByName(http_hdr_type id);
-extern void httpRequestHdrCacheInit(HttpRequest * req);
-
class HttpHdrRange;
public:
bool parseRequestLine(const char *start, const char *end);
+ int parseHeader(const char *parse_start);
private:
const char *packableURI(bool full_uri) const;
protected:
virtual void packFirstLineInto(Packer * p, bool full_uri) const;
virtual bool sanityCheckStartLine(MemBuf *buf, http_status *error);
+ virtual void hdrCacheInit();
public: // should be private
void clean(); // low-level; treat as private
/*
- * $Id: client_side.cc,v 1.695 2005/09/14 21:09:38 wessels Exp $
+ * $Id: client_side.cc,v 1.696 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
/* compile headers */
/* we should skip request line! */
- if (!httpRequestParseHeader(request, prefix + req_line_sz)) {
+ if (!request->parseHeader(prefix + req_line_sz)) {
clientStreamNode *node = context->getClientReplyContext();
debug(33, 5) ("Failed to parse request headers:\n%s\n", prefix);
clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
/*
- * $Id: client_side_reply.cc,v 1.87 2005/09/14 17:10:38 serassio Exp $
+ * $Id: client_side_reply.cc,v 1.88 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 88 Client-side Reply Routines
* AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
* www.thegist.com (Netscape/1.13) returns a content-length for
* 304's which seems to be the length of the 304 HEADERS!!! and
* not the body they refer to. */
- httpReplyUpdateOnNotModified((HttpReply *)old_entry->getReply(), http->storeEntry()->getReply());
+ HttpReply *old_rep = (HttpReply *) old_entry->getReply();
+
+ old_rep->httpReplyUpdateOnNotModified(http->storeEntry()->getReply());
storeTimestampsSet(old_entry);
http->logType = LOG_TCP_REFRESH_MISS;
if (HTTP_NOT_MODIFIED == http->storeEntry()->getReply()->sline.status) {
- httpReplyUpdateOnNotModified((HttpReply *)old_entry->getReply(),
- http->storeEntry()->getReply());
+ HttpReply *old_rep = (HttpReply *) old_entry->getReply();
+ old_rep->httpReplyUpdateOnNotModified(http->storeEntry()->getReply());
storeTimestampsSet(old_entry);
http->logType = LOG_TCP_REFRESH_HIT;
}
/*
- * $Id: client_side_request.cc,v 1.46 2005/09/12 22:26:39 wessels Exp $
+ * $Id: client_side_request.cc,v 1.47 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 85 Client-side Request Routines
* AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
s.clean();
}
- request->cache_control = httpHeaderGetCc(req_hdr);
-
if (request->cache_control)
if (EBIT_TEST(request->cache_control->mask, CC_NO_CACHE))
no_cache++;
/*
- * $Id: peer_digest.cc,v 1.103 2005/06/03 15:24:14 serassio Exp $
+ * $Id: peer_digest.cc,v 1.104 2005/09/15 19:22:30 wessels Exp $
*
* DEBUG: section 72 Peer Digest Routines
* AUTHOR: Alex Rousskov
assert(fetch->old_entry->mem_obj->request);
- httpReplyUpdateOnNotModified((HttpReply *)fetch->old_entry->getReply(), reply);
+ HttpReply *old_rep = (HttpReply *) fetch->old_entry->getReply();
+
+ old_rep->httpReplyUpdateOnNotModified(reply);
storeTimestampsSet(fetch->old_entry);