From 69660be06eee3fe963861569a21b6fa38daa88e4 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Mon, 23 Sep 2002 09:59:15 +0000 Subject: [PATCH] Add HTTP status code 307 as HTTP_TEMPORARY_REDIRECT. Also support 303/307 status codes in redirector replies. --- src/client_side_request.cc | 183 ++++++++++++++++++++----------------- src/enums.h | 21 +++-- 2 files changed, 109 insertions(+), 95 deletions(-) diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 129ba0c645..7a1ae5ac3d 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1,44 +1,44 @@ /* - * $Id: client_side_request.cc,v 1.3 2002/09/15 15:06:01 robertc Exp $ - * - * DEBUG: section 85 Client-side Request Routines - * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) - * + * $Id: client_side_request.cc,v 1.4 2002/09/23 03:59:15 wessels Exp $ + * + * DEBUG: section 85 Client-side Request Routines AUTHOR: Robert Collins + * (Originally Duane Wessels in client_side.c) + * * 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. - * + * + * 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. + * */ -/* General logic of request processing: - * - * We run a series of tests to determine if access will be permitted, - * and to do any redirection. Then we call into the result clientStream - * to retrieve data. From that point on it's up to reply management. +/* + * General logic of request processing: + * + * We run a series of tests to determine if access will be permitted, and to do + * any redirection. Then we call into the result clientStream to retrieve data. + * From that point on it's up to reply management. */ #include "squid.h" @@ -64,7 +64,8 @@ FREE clientRequestContextFree; /* other */ static int checkAccelOnly(clientHttpRequest *); static void clientAccessCheckDone(int, void *); -/*static */ aclCheck_t *clientAclChecklistCreate(const acl_access * acl, + /* static */ aclCheck_t * + clientAclChecklistCreate(const acl_access * acl, const clientHttpRequest * http); static int clientCachable(clientHttpRequest * http); static int clientHierarchical(clientHttpRequest * http); @@ -98,8 +99,9 @@ clientRequestContextNew(clientHttpRequest * http) } /* Create a request and kick it off */ -/* TODO: Pass in the buffers to be used in the inital Read request, - * as they are determined by the user +/* + * TODO: Pass in the buffers to be used in the inital Read request, as they are + * determined by the user */ int /* returns nonzero on failure */ clientBeginRequest(method_t method, char const *url, CSCB * streamcallback, @@ -123,7 +125,7 @@ clientBeginRequest(method_t method, char const *url, CSCB * streamcallback, /* make it visible in the 'current acctive requests list' */ dlinkAdd(http, &http->active, &ClientActiveRequests); /* Set flags */ - http->flags.accel = 1; /* internal requests only makes sense in an + http->flags.accel = 1; /* internal requests only makes sense in an * accelerator today. TODO: accept flags ? */ /* allow size for url rewriting */ url_sz = strlen(url) + Config.appendDomainLen + 5; @@ -134,24 +136,27 @@ clientBeginRequest(method_t method, char const *url, CSCB * streamcallback, debug(85, 5) ("Invalid URL: %s\n", http->uri); return -1; } - /* now update the headers in request with our supplied headers. - * urLParse should return a blank header set, but we use Update to be sure - * of correctness. + /* + * now update the headers in request with our supplied headers. urLParse + * should return a blank header set, but we use Update to be sure of + * correctness. */ if (header) httpHeaderUpdate(&request->header, header, NULL); http->log_uri = xstrdup(urlCanonicalClean(request)); /* http struct now ready */ - /* build new header list *? - * TODO + /* + * build new header list *? TODO */ request->flags.accelerated = http->flags.accel; - request->flags.internalclient = 1; /* this is an internally created request, not subject - * to acceleration target overrides - */ - /* FIXME? Do we want to detect and handle internal requests of internal - * objects ? */ + request->flags.internalclient = 1; /* this is an internally created + * request, not subject to acceleration + * target overrides */ + /* + * FIXME? Do we want to detect and handle internal requests of internal + * objects ? + */ /* Internally created requests cannot have bodies today */ request->content_length = 0; @@ -169,8 +174,10 @@ clientBeginRequest(method_t method, char const *url, CSCB * streamcallback, static int checkAccelOnly(clientHttpRequest * http) { - /* return TRUE if someone makes a proxy request to us and - * we are in httpd-accel only mode */ + /* + * return TRUE if someone makes a proxy request to us and we are in + * httpd-accel only mode + */ if (!Config2.Accel.on) return 0; if (Config.onoff.accel_with_proxy) @@ -192,14 +199,15 @@ clientAclChecklistCreate(const acl_access * acl, const clientHttpRequest * http) ch = aclChecklistCreate(acl, http->request, conn ? conn->rfc931 : dash_str); /* - * hack for ident ACL. It needs to get full addresses, and a - * place to store the ident result on persistent connections... + * hack for ident ACL. It needs to get full addresses, and a place to store + * the ident result on persistent connections... */ /* connection oriented auth also needs these two lines for it's operation. */ - /* Internal requests do not have a connection reference, because: - * A) their byte count may be transformed before being applied to an outbound - * connection - * B) they are internal - any limiting on them should be done on the server end. + /* + * Internal requests do not have a connection reference, because: A) their + * byte count may be transformed before being applied to an outbound + * connection B) they are internal - any limiting on them should be done on + * the server end. */ if (conn) ch->conn = cbdataReference(conn); /* unreferenced in acl.c */ @@ -257,10 +265,10 @@ clientAccessCheckDone(int answer, void *data) debug(85, 5) ("Proxy Auth Message = %s\n", proxy_auth_msg ? proxy_auth_msg : ""); /* - * NOTE: get page_id here, based on AclMatchedName because - * if USE_DELAY_POOLS is enabled, then AclMatchedName gets - * clobbered in the clientCreateStoreEntry() call - * just below. Pedro Ribeiro + * NOTE: get page_id here, based on AclMatchedName because if + * USE_DELAY_POOLS is enabled, then AclMatchedName gets clobbered in + * the clientCreateStoreEntry() call just below. Pedro Ribeiro + * */ page_id = aclGetDenyInfoPage(&Config.denyInfoList, AclMatchedName); http->logType = LOG_TCP_DENIED; @@ -301,9 +309,9 @@ clientCachable(clientHttpRequest * http) /* FTP is always cachable */ if (req->protocol == PROTO_WAIS) return 0; - /* The below looks questionable: what non HTTP - * protocols use connect, trace, put and post? - * RC + /* + * The below looks questionable: what non HTTP protocols use connect, + * trace, put and post? RC */ if (method == METHOD_CONNECT) return 0; @@ -312,7 +320,8 @@ clientCachable(clientHttpRequest * http) if (method == METHOD_PUT) return 0; if (method == METHOD_POST) - return 0; /* XXX POST may be cached sometimes.. ignored for now */ + return 0; /* XXX POST may be cached sometimes.. ignored + * for now */ if (req->protocol == PROTO_GOPHER) return gopherCachable(req); if (req->protocol == PROTO_CACHEOBJ) @@ -328,14 +337,15 @@ clientHierarchical(clientHttpRequest * http) method_t method = request->method; const wordlist *p = NULL; - /* IMS needs a private key, so we can use the hierarchy for IMS only - * if our neighbors support private keys */ + /* + * IMS needs a private key, so we can use the hierarchy for IMS only if our + * neighbors support private keys + */ if (request->flags.ims && !neighbors_do_private_keys) return 0; - /* This is incorrect: authenticating requests - * can be sent via a hierarchy (they can even - * be cached if the correct headers are set on - * the reply + /* + * This is incorrect: authenticating requests can be sent via a hierarchy + * (they can even be cached if the correct headers are set on the reply */ if (request->flags.auth) return 0; @@ -375,8 +385,9 @@ clientInterpretRequestHeaders(clientHttpRequest * http) if (request->ims > 0) request->flags.ims = 1; #if ESI - /* We ignore Cache-Control as per the Edge Architecture - * Section 3. See www.esi.org for more information. + /* + * We ignore Cache-Control as per the Edge Architecture Section 3. See + * www.esi.org for more information. */ #else if (httpHeaderHas(req_hdr, HDR_PRAGMA)) { @@ -389,12 +400,12 @@ clientInterpretRequestHeaders(clientHttpRequest * http) if (request->cache_control) if (EBIT_TEST(request->cache_control->mask, CC_NO_CACHE)) no_cache++; - /* Work around for supporting the Reload button in IE browsers - * when Squid is used as an accelerator or transparent proxy, - * by turning accelerated IMS request to no-cache requests. - * Now knows about IE 5.5 fix (is actually only fixed in SP1, - * but we can't tell whether we are talking to SP1 or not so - * all 5.5 versions are treated 'normally'). + /* + * Work around for supporting the Reload button in IE browsers when Squid + * is used as an accelerator or transparent proxy, by turning accelerated + * IMS request to no-cache requests. Now knows about IE 5.5 fix (is + * actually only fixed in SP1, but we can't tell whether we are talking to + * SP1 or not so all 5.5 versions are treated 'normally'). */ if (Config.onoff.ie_refresh) { if (http->flags.accel && request->flags.ims) { @@ -424,9 +435,8 @@ clientInterpretRequestHeaders(clientHttpRequest * http) /* ignore range header in non-GETs */ if (request->method == METHOD_GET) { /* - * Since we're not doing ranges atm, just set the flag if - * the header exists, and then free the range header info - * -- adrian + * Since we're not doing ranges atm, just set the flag if the header + * exists, and then free the range header info -- adrian */ request->range = httpHeaderGetRange(req_hdr); if (request->range) { @@ -500,7 +510,9 @@ clientRedirectDone(void *data, char *result) if (result) { http_status status = (http_status) atoi(result); if (status == HTTP_MOVED_PERMANENTLY - || status == HTTP_MOVED_TEMPORARILY) { + || status == HTTP_MOVED_TEMPORARILY + || status == HTTP_SEE_OTHER + || status == HTTP_TEMPORARY_REDIRECT) { char *t = result; if ((t = strchr(result, ':')) != NULL) { http->redirect.status = status; @@ -568,9 +580,10 @@ clientCheckNoCacheDone(int answer, void *data) clientProcessRequest(http); } -/* Identify requests that do not go through the store and client side - * stream and forward them to the appropriate location. - * All other requests, request them. +/* + * Identify requests that do not go through the store and client side stream + * and forward them to the appropriate location. All other requests, request + * them. */ void clientProcessRequest(clientHttpRequest * http) diff --git a/src/enums.h b/src/enums.h index b7826b723f..d331a525f7 100644 --- a/src/enums.h +++ b/src/enums.h @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.214 2002/09/15 06:27:49 adrian Exp $ + * $Id: enums.h,v 1.215 2002/09/23 03:59:15 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -458,6 +458,7 @@ typedef enum { HTTP_SEE_OTHER = 303, HTTP_NOT_MODIFIED = 304, HTTP_USE_PROXY = 305, + HTTP_TEMPORARY_REDIRECT = 307, HTTP_BAD_REQUEST = 400, HTTP_UNAUTHORIZED = 401, HTTP_PAYMENT_REQUIRED = 402, @@ -752,15 +753,15 @@ typedef enum { } digest_read_state_t; typedef enum { - COMM_OK = 0, - COMM_ERROR = -1, - COMM_NOMESSAGE = -3, - COMM_TIMEOUT = -4, - COMM_SHUTDOWN = -5, - COMM_INPROGRESS = -6, - COMM_ERR_CONNECT = -7, - COMM_ERR_DNS = -8, - COMM_ERR_CLOSING = -9 + COMM_OK = 0, + COMM_ERROR = -1, + COMM_NOMESSAGE = -3, + COMM_TIMEOUT = -4, + COMM_SHUTDOWN = -5, + COMM_INPROGRESS = -6, + COMM_ERR_CONNECT = -7, + COMM_ERR_DNS = -8, + COMM_ERR_CLOSING = -9 } comm_err_t; -- 2.47.2