]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpRequest.cc
update
[thirdparty/squid.git] / src / HttpRequest.cc
CommitLineData
99edd1c3 1
2/*
a00a7c85 3 * $Id: HttpRequest.cc,v 1.9 1998/07/17 04:49:59 rousskov Exp $
99edd1c3 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
14 * the National Science Foundation.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 */
31
32#include "squid.h"
33
34request_t *
35requestCreate(method_t method, protocol_t protocol, const char *urlpath)
36{
5999b776 37 request_t *req = memAllocate(MEM_REQUEST_T);
99edd1c3 38 req->method = method;
39 req->protocol = protocol;
40 if (urlpath)
41 stringReset(&req->urlpath, urlpath);
42 req->max_age = -1;
43 req->max_forwards = -1;
2246b732 44 httpHeaderInit(&req->header, hoRequest);
99edd1c3 45 return req;
46}
47
48void
49requestDestroy(request_t * req)
50{
51 assert(req);
2246b732 52#if OLD_CODE
99edd1c3 53 safe_free(req->prefix);
2246b732 54#endif
99edd1c3 55 safe_free(req->body);
56 stringClean(&req->urlpath);
57 httpHeaderClean(&req->header);
8e092300 58 if (req->cache_control)
59 httpHdrCcDestroy(req->cache_control);
d192d11f 60 if (req->range)
61 httpHdrRangeDestroy(req->range);
99edd1c3 62 memFree(MEM_REQUEST_T, req);
63}
64
65request_t *
66requestLink(request_t * request)
67{
68 assert(request);
69 request->link_count++;
70 return request;
71}
72
73void
74requestUnlink(request_t * request)
75{
76 if (!request)
77 return;
78 request->link_count--;
79 if (request->link_count > 0)
80 return;
8e092300 81 if (request->link_count == 0)
82 requestDestroy(request);
83 else
84 debug(73, 1) ("requestUnlink: BUG: negative link_count: %d. Ignored.\n",
85 request->link_count);
99edd1c3 86}
87
88int
5999b776 89httpRequestParseHeader(request_t * req, const char *parse_start)
99edd1c3 90{
91 const char *blk_start, *blk_end;
92 if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end))
93 return 0;
94 return httpHeaderParse(&req->header, blk_start, blk_end);
95}
96
a00a7c85 97/* swaps out request using httpRequestPack */
99edd1c3 98void
eeb423fb 99httpRequestSwapOut(const request_t * req, StoreEntry * e)
99edd1c3 100{
a00a7c85 101 Packer p;
2246b732 102 assert(req && e);
a00a7c85 103 packerToStoreInit(&p, e);
104 httpRequestPack(req, &p);
105 packerClean(&p);
106}
107
108/* packs request-line and headers, appends <crlf> terminator */
109void
110httpRequestPack(const request_t * req, Packer *p)
111{
112 assert(req && p);
113 /* pack request-line */
114 packerPrintf(p, "%s %s HTTP/1.0\r\n",
6c632b84 115 RequestMethodStr[req->method], strBuf(req->urlpath));
a00a7c85 116 /* headers */
117 httpHeaderPackInto(&req->header, p);
2246b732 118 /* trailer */
a00a7c85 119 packerAppend(p, "\r\n", 2);
2246b732 120}
121
122#if UNUSED_CODE
123void
eeb423fb 124httpRequestSetHeaders(request_t * req, method_t method, const char *uri, const char *header_str)
2246b732 125{
126#if OLD_CODE
99edd1c3 127 MemBuf mb;
128 assert(req && uri && header_str);
129 assert(!req->prefix);
130
131 memBufDefInit(&mb);
132 memBufPrintf(&mb, "%s %s HTTP/%3.1f\r\n%s\r\n",
133 RequestMethodStr[method], uri, req->http_ver, header_str);
134 req->prefix = xstrdup(mb.buf);
135 req->prefix_sz = mb.size;
136 memBufClean(&mb);
2246b732 137#else
138 assert(req && uri && header_str);
139 assert(!req->header.len);
140#endif
5999b776 141 httpHeaderParse(&req->header, header_str, header_str + strlen(header_str));
99edd1c3 142}
eeb423fb 143
2246b732 144#endif
145
146/* returns the length of request line + headers + crlf */
147int
eeb423fb 148httpRequestPrefixLen(const request_t * req)
2246b732 149{
150 assert(req);
151 return strlen(RequestMethodStr[req->method]) + 1 +
152 strLen(req->urlpath) + 1 +
eeb423fb 153 4 + 1 + 3 + 2 +
2246b732 154 req->header.len + 2;
155}
99edd1c3 156
157/* returns true if header is allowed to be passed on */
158int
5999b776 159httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConn)
99edd1c3 160{
161 assert(e);
162 /* check connection header first */
163 if (strConn && strListIsMember(strConn, strBuf(e->name), ','))
164 return 0;
165 /* check with anonymizer tables */
166 if (Config.onoff.anonymizer == ANONYMIZER_PARANOID) {
167 return httpAnonHdrAllowed(e->id);
5999b776 168 } else if (Config.onoff.anonymizer == ANONYMIZER_STANDARD) {
99edd1c3 169 return !httpAnonHdrDenied(e->id);
170 }
171 return 1;
172}