]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpRequest.cc
Luyers finished delay pools patch
[thirdparty/squid.git] / src / HttpRequest.cc
1
2 /*
3 * $Id: HttpRequest.cc,v 1.18 1998/08/14 09:22:31 wessels Exp $
4 *
5 * DEBUG: section 73 HTTP Request
6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * Duane Wessels and the University of California San Diego. Please
16 * see the COPYRIGHT file for full details. Squid incorporates
17 * software developed and/or copyrighted by other sources. Please see
18 * the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #include "squid.h"
37
38 request_t *
39 requestCreate(method_t method, protocol_t protocol, const char *urlpath)
40 {
41 request_t *req = memAllocate(MEM_REQUEST_T);
42 req->method = method;
43 req->protocol = protocol;
44 if (urlpath)
45 stringReset(&req->urlpath, urlpath);
46 req->max_age = -1;
47 req->max_forwards = -1;
48 #if DELAY_POOLS
49 req->delay_id = 0;
50 #endif
51 httpHeaderInit(&req->header, hoRequest);
52 return req;
53 }
54
55 void
56 requestDestroy(request_t * req)
57 {
58 assert(req);
59 safe_free(req->body);
60 safe_free(req->canonical);
61 stringClean(&req->urlpath);
62 httpHeaderClean(&req->header);
63 if (req->cache_control)
64 httpHdrCcDestroy(req->cache_control);
65 if (req->range)
66 httpHdrRangeDestroy(req->range);
67 memFree(MEM_REQUEST_T, req);
68 }
69
70 request_t *
71 requestLink(request_t * request)
72 {
73 assert(request);
74 request->link_count++;
75 return request;
76 }
77
78 void
79 requestUnlink(request_t * request)
80 {
81 if (!request)
82 return;
83 assert(request->link_count > 0);
84 if (--request->link_count > 0)
85 return;
86 requestDestroy(request);
87 }
88
89 int
90 httpRequestParseHeader(request_t * req, const char *parse_start)
91 {
92 const char *blk_start, *blk_end;
93 if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end))
94 return 0;
95 return httpHeaderParse(&req->header, blk_start, blk_end);
96 }
97
98 /* swaps out request using httpRequestPack */
99 void
100 httpRequestSwapOut(const request_t * req, StoreEntry * e)
101 {
102 Packer p;
103 assert(req && e);
104 packerToStoreInit(&p, e);
105 httpRequestPack(req, &p);
106 packerClean(&p);
107 }
108
109 /* packs request-line and headers, appends <crlf> terminator */
110 void
111 httpRequestPack(const request_t * req, Packer * p)
112 {
113 assert(req && p);
114 /* pack request-line */
115 packerPrintf(p, "%s %s HTTP/1.0\r\n",
116 RequestMethodStr[req->method], strBuf(req->urlpath));
117 /* headers */
118 httpHeaderPackInto(&req->header, p);
119 /* trailer */
120 packerAppend(p, "\r\n", 2);
121 }
122
123 #if UNUSED_CODE
124 void
125 httpRequestSetHeaders(request_t * req, method_t method, const char *uri, const char *header_str)
126 {
127 assert(req && uri && header_str);
128 assert(!req->header.len);
129 httpHeaderParse(&req->header, header_str, header_str + strlen(header_str));
130 }
131
132 #endif
133
134 /* returns the length of request line + headers + crlf */
135 int
136 httpRequestPrefixLen(const request_t * req)
137 {
138 assert(req);
139 return strlen(RequestMethodStr[req->method]) + 1 +
140 strLen(req->urlpath) + 1 +
141 4 + 1 + 3 + 2 +
142 req->header.len + 2;
143 }
144
145 /* returns true if header is allowed to be passed on */
146 int
147 httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConn)
148 {
149 assert(e);
150 /* check connection header first */
151 if (strConn && strListIsMember(strConn, strBuf(e->name), ','))
152 return 0;
153 /* check with anonymizer tables */
154 if (Config.onoff.anonymizer == ANONYMIZER_PARANOID) {
155 return httpAnonHdrAllowed(e->id);
156 } else if (Config.onoff.anonymizer == ANONYMIZER_STANDARD) {
157 return !httpAnonHdrDenied(e->id);
158 }
159 return 1;
160 }