--------------------- PatchSet 5056 Date: 2002/09/20 04:03:03 Author: rbcollins Branch: fixrange Tag: (none) Log: pull HttpStateData into a separate header to allow easy factoring. Factor out header copying logic from httpBuildRequestHeader Members: src/HttpHeader.c:1.16->1.16.6.1 src/cbdata.c:1.15.14.1->1.15.14.2 src/enums.h:1.38.2.1->1.38.2.2 src/http.c:1.24.2.1->1.24.2.2 src/http.h:1.1->1.1.2.1 src/protos.h:1.61.2.5->1.61.2.6 src/structs.h:1.68.2.3->1.68.2.4 src/typedefs.h:1.28.2.2->1.28.2.3 Index: squid/src/HttpHeader.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHeader.c,v retrieving revision 1.16 retrieving revision 1.16.6.1 diff -u -r1.16 -r1.16.6.1 --- squid/src/HttpHeader.c 11 Aug 2002 21:45:40 -0000 1.16 +++ squid/src/HttpHeader.c 20 Sep 2002 04:03:03 -0000 1.16.6.1 @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.c,v 1.16 2002/08/11 21:45:40 squidadm Exp $ + * $Id: HttpHeader.c,v 1.16.6.1 2002/09/20 04:03:03 rbcollins Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -829,18 +829,30 @@ } int -httpHeaderGetInt(const HttpHeader * hdr, http_hdr_type id) +httpHeaderEntryGetInt (const HttpHeaderEntry * e) { - HttpHeaderEntry *e; int value = -1; int ok; + assert (e); + assert_eid (e->id); + assert (Headers[e->id].type == ftInt); + ok = httpHeaderParseInt(strBuf(e->value), &value); + httpHeaderNoteParsedEntry(e->id, e->value, !ok); + /* XXX: Should we check ok - ie + * return ok ? -1 : value; + */ + return value; +} + +int +httpHeaderGetInt(const HttpHeader * hdr, http_hdr_type id) +{ + HttpHeaderEntry *e; assert_eid(id); assert(Headers[id].type == ftInt); /* must be of an appropriate type */ - if ((e = httpHeaderFindEntry(hdr, id))) { - ok = httpHeaderParseInt(strBuf(e->value), &value); - httpHeaderNoteParsedEntry(e->id, e->value, !ok); - } - return value; + if ((e = httpHeaderFindEntry(hdr, id))) + return httpHeaderEntryGetInt (e); + return -1; } time_t Index: squid/src/cbdata.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cbdata.c,v retrieving revision 1.15.14.1 retrieving revision 1.15.14.2 diff -u -r1.15.14.1 -r1.15.14.2 --- squid/src/cbdata.c 16 Sep 2002 13:27:45 -0000 1.15.14.1 +++ squid/src/cbdata.c 20 Sep 2002 04:03:03 -0000 1.15.14.2 @@ -1,6 +1,6 @@ /* - * $Id: cbdata.c,v 1.15.14.1 2002/09/16 13:27:45 rbcollins Exp $ + * $Id: cbdata.c,v 1.15.14.2 2002/09/20 04:03:03 rbcollins Exp $ * * DEBUG: section 45 Callback Data Registry * ORIGINAL AUTHOR: Duane Wessels @@ -132,7 +132,6 @@ CREATE_CBDATA(helper_server); CREATE_CBDATA(statefulhelper); CREATE_CBDATA(helper_stateful_server); - CREATE_CBDATA(HttpStateData); CREATE_CBDATA_FREE(peer, peerDestroy); CREATE_CBDATA(ps_state); CREATE_CBDATA(RemovalPolicy); Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.38.2.1 retrieving revision 1.38.2.2 diff -u -r1.38.2.1 -r1.38.2.2 --- squid/src/enums.h 16 Sep 2002 13:27:46 -0000 1.38.2.1 +++ squid/src/enums.h 20 Sep 2002 04:03:03 -0000 1.38.2.2 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.38.2.1 2002/09/16 13:27:46 rbcollins Exp $ + * $Id: enums.h,v 1.38.2.2 2002/09/20 04:03:03 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -719,7 +719,6 @@ CBDATA_helper_server, CBDATA_statefulhelper, CBDATA_helper_stateful_server, - CBDATA_HttpStateData, CBDATA_peer, CBDATA_ps_state, CBDATA_RemovalPolicy, Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.24.2.1 retrieving revision 1.24.2.2 diff -u -r1.24.2.1 -r1.24.2.2 --- squid/src/http.c 16 Sep 2002 13:27:46 -0000 1.24.2.1 +++ squid/src/http.c 20 Sep 2002 04:03:04 -0000 1.24.2.2 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.24.2.1 2002/09/16 13:27:46 rbcollins Exp $ + * $Id: http.c,v 1.24.2.2 2002/09/20 04:03:04 rbcollins Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -39,6 +39,7 @@ */ #include "squid.h" +#include "http.h" static const char *const crlf = "\r\n"; @@ -715,6 +716,82 @@ } } +void +copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, String strConnection, request_t * request, request_t * orig_request, HttpHeader * hdr_out) +{ + debug(11, 5) ("httpBuildRequestHeader: %s: %s\n", + strBuf(e->name), strBuf(e->value)); + if (!httpRequestHdrAllowed(e, &strConnection)) { + debug(11, 2) ("'%s' header denied by anonymize_headers configuration\n", + strBuf(e->name)); + return; + } + switch (e->id) { + case HDR_PROXY_AUTHORIZATION: + /* Only pass on proxy authentication to peers for which + * authentication forwarding is explicitly enabled + */ + if (request->flags.proxying && orig_request->peer_login && + strcmp(orig_request->peer_login, "PASS") == 0) { + httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); + } + break; + case HDR_AUTHORIZATION: + /* Pass on WWW authentication even if used locally. If this is + * not wanted in an accelerator then the header can be removed + * using the anonymization functions + */ + httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); + /* XXX Some accelerators might want to strip the header + * and regard the reply as cacheable, but authentication + * is not normally enabled for accelerators without reading + * the code, so there is not much use in adding logics here + * without first defining the concept of having authentication + * in the accelerator... + */ + break; + case HDR_HOST: + /* + * Normally Squid does not copy the Host: header from + * a client request into the forwarded request headers. + * However, there is one case when we do: If the URL + * went through our redirector and the admin configured + * 'redir_rewrites_host' to be off. + */ + if (request->flags.redirected) + if (!Config.onoff.redir_rewrites_host) + httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); + break; + case HDR_IF_MODIFIED_SINCE: + /* append unless we added our own; + * note: at most one client's ims header can pass through */ + if (!httpHeaderHas(hdr_out, HDR_IF_MODIFIED_SINCE)) + httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); + break; + case HDR_MAX_FORWARDS: + if (orig_request->method == METHOD_TRACE) { + const int hops = httpHeaderEntryGetInt(e); + if (hops > 0) + httpHeaderPutInt(hdr_out, HDR_MAX_FORWARDS, hops - 1); + } + break; + case HDR_VIA: + /* If Via is disabled then forward any received header as-is */ + if (!Config.onoff.via) + httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); + break; + case HDR_PROXY_CONNECTION: + case HDR_CONNECTION: + case HDR_X_FORWARDED_FOR: + case HDR_CACHE_CONTROL: + /* append these after the loop if needed */ + break; + default: + /* pass on all other header fields */ + httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); + } +} + /* * build request headers and append them to a given MemBuf * used by httpBuildRequestPrefix() @@ -742,80 +819,8 @@ httpHeaderPutTime(hdr_out, HDR_IF_MODIFIED_SINCE, request->lastmod); strConnection = httpHeaderGetList(hdr_in, HDR_CONNECTION); - while ((e = httpHeaderGetEntry(hdr_in, &pos))) { - debug(11, 5) ("httpBuildRequestHeader: %s: %s\n", - strBuf(e->name), strBuf(e->value)); - if (!httpRequestHdrAllowed(e, &strConnection)) { - debug(11, 2) ("'%s' header denied by anonymize_headers configuration\n", - strBuf(e->name)); - continue; - } - switch (e->id) { - case HDR_PROXY_AUTHORIZATION: - /* Only pass on proxy authentication to peers for which - * authentication forwarding is explicitly enabled - */ - if (request->flags.proxying && orig_request->peer_login && - strcmp(orig_request->peer_login, "PASS") == 0) { - httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); - } - break; - case HDR_AUTHORIZATION: - /* Pass on WWW authentication even if used locally. If this is - * not wanted in an accelerator then the header can be removed - * using the anonymization functions - */ - httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); - /* XXX Some accelerators might want to strip the header - * and regard the reply as cacheable, but authentication - * is not normally enabled for accelerators without reading - * the code, so there is not much use in adding logics here - * without first defining the concept of having authentication - * in the accelerator... - */ - break; - case HDR_HOST: - /* - * Normally Squid does not copy the Host: header from - * a client request into the forwarded request headers. - * However, there is one case when we do: If the URL - * went through our redirector and the admin configured - * 'redir_rewrites_host' to be off. - */ - if (request->flags.redirected) - if (!Config.onoff.redir_rewrites_host) - httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); - break; - case HDR_IF_MODIFIED_SINCE: - /* append unless we added our own; - * note: at most one client's ims header can pass through */ - if (!httpHeaderHas(hdr_out, HDR_IF_MODIFIED_SINCE)) - httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); - break; - case HDR_MAX_FORWARDS: - if (orig_request->method == METHOD_TRACE) { - /* sacrificing efficiency over clarity, etc. */ - const int hops = httpHeaderGetInt(hdr_in, HDR_MAX_FORWARDS); - if (hops > 0) - httpHeaderPutInt(hdr_out, HDR_MAX_FORWARDS, hops - 1); - } - break; - case HDR_VIA: - /* If Via is disabled then forward any received header as-is */ - if (!Config.onoff.via) - httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); - break; - case HDR_PROXY_CONNECTION: - case HDR_CONNECTION: - case HDR_X_FORWARDED_FOR: - case HDR_CACHE_CONTROL: - /* append these after the loop if needed */ - break; - default: - /* pass on all other header fields */ - httpHeaderAddEntry(hdr_out, httpHeaderEntryClone(e)); - } - } + while ((e = httpHeaderGetEntry(hdr_in, &pos))) + copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, orig_request, hdr_out); /* append Via */ if (Config.onoff.via) { @@ -990,6 +995,7 @@ debug(11, 3) ("httpStart: \"%s %s\"\n", RequestMethodStr[orig_req->method], storeUrl(fwd->entry)); + CBDATA_INIT_TYPE(HttpStateData); httpState = cbdataAlloc(HttpStateData); storeLockObject(fwd->entry); httpState->fwd = fwd; --- /dev/null Wed Feb 14 01:05:20 2007 +++ squid/src/http.h Wed Feb 14 01:06:39 2007 @@ -0,0 +1,53 @@ + +/* + * $Id: http.h,v 1.1.2.1 2002/09/20 04:03:04 rbcollins Exp $ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_HTTP_H +#define SQUID_HTTP_H + +typedef struct _HttpStateData HttpStateData; +struct _HttpStateData { + StoreEntry *entry; + request_t *request; + char *reply_hdr; + size_t reply_hdr_size; + int reply_hdr_state; + peer *_peer; /* peer request made to */ + int eof; /* reached end-of-object? */ + request_t *orig_request; + int fd; + http_state_flags flags; + FwdState *fwd; +}; +CBDATA_TYPE(HttpStateData); + +#endif /* SQUID_HTTP_H */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.61.2.5 retrieving revision 1.61.2.6 diff -u -r1.61.2.5 -r1.61.2.6 --- squid/src/protos.h 19 Sep 2002 08:21:49 -0000 1.61.2.5 +++ squid/src/protos.h 20 Sep 2002 04:03:04 -0000 1.61.2.6 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.61.2.5 2002/09/19 08:21:49 rbcollins Exp $ + * $Id: protos.h,v 1.61.2.6 2002/09/20 04:03:04 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -306,7 +306,6 @@ extern int httpCachable(method_t); extern void httpStart(FwdState *); extern void httpParseReplyHeaders(const char *, http_reply *); -extern void httpProcessReplyHeader(HttpStateData *, const char *, int); extern mb_size_t httpBuildRequestPrefix(request_t * request, request_t * orig_request, StoreEntry * entry, @@ -463,6 +462,7 @@ extern int httpHeaderDelByName(HttpHeader * hdr, const char *name); extern int httpHeaderDelById(HttpHeader * hdr, http_hdr_type id); extern void httpHeaderDelAt(HttpHeader * hdr, HttpHeaderPos pos); +extern int httpHeaderEntryGetInt (const HttpHeaderEntry * e); /* avoid using these low level routines */ extern HttpHeaderEntry *httpHeaderGetEntry(const HttpHeader * hdr, HttpHeaderPos * pos); extern HttpHeaderEntry *httpHeaderFindEntry(const HttpHeader * hdr, http_hdr_type id); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.68.2.3 retrieving revision 1.68.2.4 diff -u -r1.68.2.3 -r1.68.2.4 --- squid/src/structs.h 19 Sep 2002 08:09:55 -0000 1.68.2.3 +++ squid/src/structs.h 20 Sep 2002 04:03:05 -0000 1.68.2.4 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.68.2.3 2002/09/19 08:09:55 rbcollins Exp $ + * $Id: structs.h,v 1.68.2.4 2002/09/20 04:03:05 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -968,20 +968,6 @@ unsigned int only_if_cached:1; }; -struct _HttpStateData { - StoreEntry *entry; - request_t *request; - char *reply_hdr; - size_t reply_hdr_size; - int reply_hdr_state; - peer *_peer; /* peer request made to */ - int eof; /* reached end-of-object? */ - request_t *orig_request; - int fd; - http_state_flags flags; - FwdState *fwd; -}; - struct _icpUdpData { struct sockaddr_in address; void *msg; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.28.2.2 retrieving revision 1.28.2.3 diff -u -r1.28.2.2 -r1.28.2.3 --- squid/src/typedefs.h 16 Sep 2002 23:21:59 -0000 1.28.2.2 +++ squid/src/typedefs.h 20 Sep 2002 04:03:06 -0000 1.28.2.3 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.28.2.2 2002/09/16 23:21:59 rbcollins Exp $ + * $Id: typedefs.h,v 1.28.2.3 2002/09/20 04:03:06 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -106,7 +106,6 @@ typedef struct _HttpHeaderStat HttpHeaderStat; typedef struct _HttpBody HttpBody; typedef struct _HttpReply HttpReply; -typedef struct _HttpStateData HttpStateData; typedef struct _icpUdpData icpUdpData; typedef struct _clientHttpRequest clientHttpRequest; typedef struct _ConnStateData ConnStateData;