]>
Commit | Line | Data |
---|---|---|
99edd1c3 | 1 | |
2 | /* | |
2b6662ba | 3 | * $Id: HttpRequest.cc,v 1.29 2001/01/12 00:37:14 wessels Exp $ |
99edd1c3 | 4 | * |
5 | * DEBUG: section 73 HTTP Request | |
6 | * AUTHOR: Duane Wessels | |
7 | * | |
2b6662ba | 8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 9 | * ---------------------------------------------------------- |
99edd1c3 | 10 | * |
2b6662ba | 11 | * Squid is the result of efforts by numerous individuals from |
12 | * the Internet community; see the CONTRIBUTORS file for full | |
13 | * details. Many organizations have provided support for Squid's | |
14 | * development; see the SPONSORS file for full details. Squid is | |
15 | * Copyrighted (C) 2001 by the Regents of the University of | |
16 | * California; see the COPYRIGHT file for full details. Squid | |
17 | * incorporates software developed and/or copyrighted by other | |
18 | * sources; see the CREDITS file for full details. | |
99edd1c3 | 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 | |
cbdec147 | 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 33 | * |
99edd1c3 | 34 | */ |
35 | ||
36 | #include "squid.h" | |
37 | ||
38 | request_t * | |
39 | requestCreate(method_t method, protocol_t protocol, const char *urlpath) | |
40 | { | |
5999b776 | 41 | request_t *req = memAllocate(MEM_REQUEST_T); |
99edd1c3 | 42 | req->method = method; |
43 | req->protocol = protocol; | |
44 | if (urlpath) | |
45 | stringReset(&req->urlpath, urlpath); | |
99edd1c3 | 46 | req->max_forwards = -1; |
9bc73deb | 47 | req->lastmod = -1; |
7e3ce7b9 | 48 | req->client_addr = no_addr; |
49 | req->my_addr = no_addr; | |
2246b732 | 50 | httpHeaderInit(&req->header, hoRequest); |
99edd1c3 | 51 | return req; |
52 | } | |
53 | ||
54 | void | |
55 | requestDestroy(request_t * req) | |
56 | { | |
57 | assert(req); | |
94439e4e | 58 | if (req->body_connection) |
59 | clientAbortBody(req); | |
60 | if (req->auth_user_request) | |
61 | authenticateAuthUserRequestUnlock(req->auth_user_request); | |
b0431342 | 62 | safe_free(req->canonical); |
99edd1c3 | 63 | stringClean(&req->urlpath); |
64 | httpHeaderClean(&req->header); | |
8e092300 | 65 | if (req->cache_control) |
66 | httpHdrCcDestroy(req->cache_control); | |
d192d11f | 67 | if (req->range) |
68 | httpHdrRangeDestroy(req->range); | |
db1cd23c | 69 | memFree(req, MEM_REQUEST_T); |
99edd1c3 | 70 | } |
71 | ||
72 | request_t * | |
73 | requestLink(request_t * request) | |
74 | { | |
75 | assert(request); | |
76 | request->link_count++; | |
77 | return request; | |
78 | } | |
79 | ||
80 | void | |
81 | requestUnlink(request_t * request) | |
82 | { | |
83 | if (!request) | |
84 | return; | |
1cc5cec5 | 85 | assert(request->link_count > 0); |
a7eb786a | 86 | if (--request->link_count > 0) |
99edd1c3 | 87 | return; |
a7eb786a | 88 | requestDestroy(request); |
99edd1c3 | 89 | } |
90 | ||
91 | int | |
5999b776 | 92 | httpRequestParseHeader(request_t * req, const char *parse_start) |
99edd1c3 | 93 | { |
94 | const char *blk_start, *blk_end; | |
95 | if (!httpMsgIsolateHeaders(&parse_start, &blk_start, &blk_end)) | |
96 | return 0; | |
97 | return httpHeaderParse(&req->header, blk_start, blk_end); | |
98 | } | |
99 | ||
a00a7c85 | 100 | /* swaps out request using httpRequestPack */ |
99edd1c3 | 101 | void |
eeb423fb | 102 | httpRequestSwapOut(const request_t * req, StoreEntry * e) |
99edd1c3 | 103 | { |
a00a7c85 | 104 | Packer p; |
2246b732 | 105 | assert(req && e); |
a00a7c85 | 106 | packerToStoreInit(&p, e); |
107 | httpRequestPack(req, &p); | |
108 | packerClean(&p); | |
109 | } | |
110 | ||
111 | /* packs request-line and headers, appends <crlf> terminator */ | |
112 | void | |
0cdcddb9 | 113 | httpRequestPack(const request_t * req, Packer * p) |
a00a7c85 | 114 | { |
115 | assert(req && p); | |
116 | /* pack request-line */ | |
117 | packerPrintf(p, "%s %s HTTP/1.0\r\n", | |
6c632b84 | 118 | RequestMethodStr[req->method], strBuf(req->urlpath)); |
a00a7c85 | 119 | /* headers */ |
120 | httpHeaderPackInto(&req->header, p); | |
2246b732 | 121 | /* trailer */ |
a00a7c85 | 122 | packerAppend(p, "\r\n", 2); |
2246b732 | 123 | } |
124 | ||
125 | #if UNUSED_CODE | |
126 | void | |
eeb423fb | 127 | httpRequestSetHeaders(request_t * req, method_t method, const char *uri, const char *header_str) |
2246b732 | 128 | { |
2246b732 | 129 | assert(req && uri && header_str); |
130 | assert(!req->header.len); | |
5999b776 | 131 | httpHeaderParse(&req->header, header_str, header_str + strlen(header_str)); |
99edd1c3 | 132 | } |
eeb423fb | 133 | |
2246b732 | 134 | #endif |
135 | ||
136 | /* returns the length of request line + headers + crlf */ | |
137 | int | |
eeb423fb | 138 | httpRequestPrefixLen(const request_t * req) |
2246b732 | 139 | { |
140 | assert(req); | |
141 | return strlen(RequestMethodStr[req->method]) + 1 + | |
142 | strLen(req->urlpath) + 1 + | |
eeb423fb | 143 | 4 + 1 + 3 + 2 + |
2246b732 | 144 | req->header.len + 2; |
145 | } | |
99edd1c3 | 146 | |
6bccf575 | 147 | /* |
148 | * Returns true if HTTP allows us to pass this header on. Does not | |
149 | * check anonymizer (aka header_access) configuration. | |
150 | */ | |
99edd1c3 | 151 | int |
5999b776 | 152 | httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConn) |
99edd1c3 | 153 | { |
154 | assert(e); | |
97474590 | 155 | /* check connection header */ |
99edd1c3 | 156 | if (strConn && strListIsMember(strConn, strBuf(e->name), ',')) |
157 | return 0; | |
99edd1c3 | 158 | return 1; |
159 | } |