]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpRequest.cc
3 * $Id: HttpRequest.cc,v 1.18 1998/08/14 09:22:31 wessels Exp $
5 * DEBUG: section 73 HTTP Request
6 * AUTHOR: Duane Wessels
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
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.
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.
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.
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.
39 requestCreate(method_t method
, protocol_t protocol
, const char *urlpath
)
41 request_t
*req
= memAllocate(MEM_REQUEST_T
);
43 req
->protocol
= protocol
;
45 stringReset(&req
->urlpath
, urlpath
);
47 req
->max_forwards
= -1;
51 httpHeaderInit(&req
->header
, hoRequest
);
56 requestDestroy(request_t
* req
)
60 safe_free(req
->canonical
);
61 stringClean(&req
->urlpath
);
62 httpHeaderClean(&req
->header
);
63 if (req
->cache_control
)
64 httpHdrCcDestroy(req
->cache_control
);
66 httpHdrRangeDestroy(req
->range
);
67 memFree(MEM_REQUEST_T
, req
);
71 requestLink(request_t
* request
)
74 request
->link_count
++;
79 requestUnlink(request_t
* request
)
83 assert(request
->link_count
> 0);
84 if (--request
->link_count
> 0)
86 requestDestroy(request
);
90 httpRequestParseHeader(request_t
* req
, const char *parse_start
)
92 const char *blk_start
, *blk_end
;
93 if (!httpMsgIsolateHeaders(&parse_start
, &blk_start
, &blk_end
))
95 return httpHeaderParse(&req
->header
, blk_start
, blk_end
);
98 /* swaps out request using httpRequestPack */
100 httpRequestSwapOut(const request_t
* req
, StoreEntry
* e
)
104 packerToStoreInit(&p
, e
);
105 httpRequestPack(req
, &p
);
109 /* packs request-line and headers, appends <crlf> terminator */
111 httpRequestPack(const request_t
* req
, Packer
* p
)
114 /* pack request-line */
115 packerPrintf(p
, "%s %s HTTP/1.0\r\n",
116 RequestMethodStr
[req
->method
], strBuf(req
->urlpath
));
118 httpHeaderPackInto(&req
->header
, p
);
120 packerAppend(p
, "\r\n", 2);
125 httpRequestSetHeaders(request_t
* req
, method_t method
, const char *uri
, const char *header_str
)
127 assert(req
&& uri
&& header_str
);
128 assert(!req
->header
.len
);
129 httpHeaderParse(&req
->header
, header_str
, header_str
+ strlen(header_str
));
134 /* returns the length of request line + headers + crlf */
136 httpRequestPrefixLen(const request_t
* req
)
139 return strlen(RequestMethodStr
[req
->method
]) + 1 +
140 strLen(req
->urlpath
) + 1 +
145 /* returns true if header is allowed to be passed on */
147 httpRequestHdrAllowed(const HttpHeaderEntry
* e
, String
* strConn
)
150 /* check connection header first */
151 if (strConn
&& strListIsMember(strConn
, strBuf(e
->name
), ','))
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
);