Index: squid/src/HttpReply.c diff -c squid/src/HttpReply.c:1.49 squid/src/HttpReply.c:1.49.2.1 *** squid/src/HttpReply.c:1.49 Wed Oct 24 02:19:08 2001 --- squid/src/HttpReply.c Tue May 6 14:13:02 2003 *************** *** 82,88 **** { assert(rep); rep->hdr_sz = 0; - rep->maxBodySize = 0; rep->pstate = psReadyToParseStartLine; httpBodyInit(&rep->body); httpHeaderInit(&rep->header, hoReply); --- 82,87 ---- *************** *** 463,491 **** else if (reply->sline.status < HTTP_OK) return 0; return reply->content_length; - } - - /* - * Calculates the maximum size allowed for an HTTP response - */ - void - httpReplyBodyBuildSize(request_t * request, HttpReply * reply, dlink_list * bodylist) - { - body_size *bs; - aclCheck_t *checklist; - bs = (body_size *) bodylist->head; - while (bs) { - checklist = aclChecklistCreate(bs->access_list, request, NULL); - checklist->reply = reply; - if (1 != aclCheckFast(bs->access_list, checklist)) { - /* deny - skip this entry */ - bs = (body_size *) bs->node.next; - } else { - /* Allow - use this entry */ - reply->maxBodySize = bs->maxsize; - bs = NULL; - debug(58, 3) ("httpReplyBodyBuildSize: Setting maxBodySize to %ld\n", (long int) reply->maxBodySize); - } - aclChecklistFree(checklist); - } } --- 462,465 ---- Index: squid/src/client_side.c diff -c squid/src/client_side.c:1.561.2.33 squid/src/client_side.c:1.561.2.34 *** squid/src/client_side.c:1.561.2.33 Wed Feb 19 16:39:12 2003 --- squid/src/client_side.c Tue May 6 14:13:02 2003 *************** *** 124,130 **** static int clientCheckContentLength(request_t * r); static DEFER httpAcceptDefer; static log_type clientProcessRequest2(clientHttpRequest * http); ! static int clientReplyBodyTooLarge(HttpReply *, ssize_t clen); static int clientRequestBodyTooLarge(int clen); static void clientProcessBody(ConnStateData * conn); --- 124,130 ---- static int clientCheckContentLength(request_t * r); static DEFER httpAcceptDefer; static log_type clientProcessRequest2(clientHttpRequest * http); ! static int clientReplyBodyTooLarge(clientHttpRequest *, ssize_t clen); static int clientRequestBodyTooLarge(int clen); static void clientProcessBody(ConnStateData * conn); *************** *** 1806,1819 **** return i->debt_size > 0; } static int ! clientReplyBodyTooLarge(HttpReply * rep, ssize_t clen) { ! if (0 == rep->maxBodySize) return 0; /* disabled */ if (clen < 0) return 0; /* unknown */ ! if (clen > rep->maxBodySize) return 1; /* too large */ return 0; } --- 1806,1844 ---- return i->debt_size > 0; } + /* + * Calculates the maximum size allowed for an HTTP response + */ + static void + clientMaxBodySize(request_t * request, clientHttpRequest * http, HttpReply * reply) + { + body_size *bs; + aclCheck_t *checklist; + bs = (body_size *) Config.ReplyBodySize.head; + while (bs) { + checklist = clientAclChecklistCreate(bs->access_list, http); + checklist->reply = reply; + if (1 != aclCheckFast(bs->access_list, checklist)) { + /* deny - skip this entry */ + bs = (body_size *) bs->node.next; + } else { + /* Allow - use this entry */ + http->maxBodySize = bs->maxsize; + bs = NULL; + debug(58, 3) ("httpReplyBodyBuildSize: Setting maxBodySize to %ld\n", (long int) http->maxBodySize); + } + aclChecklistFree(checklist); + } + } + static int ! clientReplyBodyTooLarge(clientHttpRequest * http, ssize_t clen) { ! if (0 == http->maxBodySize) return 0; /* disabled */ if (clen < 0) return 0; /* unknown */ ! if (clen > http->maxBodySize) return 1; /* too large */ return 0; } *************** *** 1857,1863 **** } } - /* * accepts chunk of a http message in buf, parses prefix, filters headers and * such, writes processed message to the client's socket --- 1882,1887 ---- *************** *** 1918,1925 **** if (rep) { aclCheck_t *ch; int rv; ! httpReplyBodyBuildSize(http->request, rep, &Config.ReplyBodySize); ! if (clientReplyBodyTooLarge(rep, rep->content_length)) { ErrorState *err = errorCon(ERR_TOO_BIG, HTTP_FORBIDDEN); err->request = requestLink(http->request); storeUnregister(http->sc, http->entry, http); --- 1942,1949 ---- if (rep) { aclCheck_t *ch; int rv; ! clientMaxBodySize(http->request, http, rep); ! if (clientReplyBodyTooLarge(http, rep->content_length)) { ErrorState *err = errorCon(ERR_TOO_BIG, HTTP_FORBIDDEN); err->request = requestLink(http->request); storeUnregister(http->sc, http->entry, http); *************** *** 2172,2178 **** } else { comm_close(fd); } ! } else if (clientReplyBodyTooLarge(entry->mem_obj->reply, http->out.offset)) { comm_close(fd); } else { /* More data will be coming from primary server; register with --- 2196,2203 ---- } else { comm_close(fd); } ! } else if (clientReplyBodyTooLarge(http, http->out.offset - 4096)) { ! /* 4096 is a margin for the HTTP headers included in out.offset */ comm_close(fd); } else { /* More data will be coming from primary server; register with Index: squid/src/protos.h diff -c squid/src/protos.h:1.420.2.17 squid/src/protos.h:1.420.2.18 *** squid/src/protos.h:1.420.2.17 Thu Jan 2 16:10:46 2003 --- squid/src/protos.h Tue May 6 14:13:02 2003 *************** *** 509,515 **** extern int httpReplyHasCc(const HttpReply * rep, http_hdr_cc_type type); extern void httpRedirectReply(HttpReply *, http_status, const char *); extern int httpReplyBodySize(method_t, HttpReply *); - extern void httpReplyBodyBuildSize(request_t *, HttpReply *, dlink_list *); /* Http Request */ extern request_t *requestCreate(method_t, protocol_t, const char *urlpath); --- 509,514 ---- Index: squid/src/structs.h diff -c squid/src/structs.h:1.408.2.9 squid/src/structs.h:1.408.2.10 *** squid/src/structs.h:1.408.2.9 Mon Jan 20 17:06:39 2003 --- squid/src/structs.h Tue May 6 14:13:03 2003 *************** *** 959,965 **** HttpStatusLine sline; HttpHeader header; HttpBody body; /* for small constant memory-resident text bodies only */ - size_t maxBodySize; }; struct _http_state_flags { --- 959,964 ---- *************** *** 1083,1088 **** --- 1082,1088 ---- char *location; } redirect; dlink_node active; + size_t maxBodySize; }; struct _ConnStateData {