From: wessels <> Date: Fri, 16 Oct 1998 05:40:04 +0000 (+0000) Subject: support 301: 302: redirector hacks X-Git-Tag: SQUID_3_0_PRE1~2571 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d38ef86b04a7dcd09f3e2c32d7f315959f29ca2;p=thirdparty%2Fsquid.git support 301: 302: redirector hacks --- diff --git a/src/HttpReply.cc b/src/HttpReply.cc index f75067647e..4ad933b7e5 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.cc,v 1.31 1998/08/18 05:44:53 rousskov Exp $ + * $Id: HttpReply.cc,v 1.32 1998/10/15 23:40:04 wessels Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -244,6 +244,21 @@ httpReplySetHeaders(HttpReply * reply, double ver, http_status status, const cha reply->last_modified = lmt; } +void +httpRedirectReply(HttpReply * reply, http_status status, const char *loc) +{ + HttpHeader *hdr; + assert(reply); + httpStatusLineSet(&reply->sline, 1.0, status, httpStatusString(status)); + hdr = &reply->header; + httpHeaderPutStr(hdr, HDR_SERVER, full_appname_string); + httpHeaderPutTime(hdr, HDR_DATE, squid_curtime); + httpHeaderPutInt(hdr, HDR_CONTENT_LENGTH, 0); + httpHeaderPutStr(hdr, HDR_LOCATION, loc); + reply->date = squid_curtime; + reply->content_length = 0; +} + void httpReplyUpdateOnNotModified(HttpReply * rep, HttpReply * freshRep) { diff --git a/src/client_side.cc b/src/client_side.cc index c6d149e9f9..879bdf6be3 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.412 1998/10/14 21:11:58 wessels Exp $ + * $Id: client_side.cc,v 1.413 1998/10/15 23:40:05 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -224,8 +224,20 @@ clientRedirectDone(void *data, char *result) result ? result : "NULL"); assert(http->redirect_state == REDIRECT_PENDING); http->redirect_state = REDIRECT_DONE; - if (result && strcmp(result, http->uri)) - new_request = urlParse(old_request->method, result); + if (result) { + http_status status = atoi(result); + if (status == 301 || status == 302) { + char *t = result; + if ((t = strchr(result, ':')) != NULL) { + http->redirect.status = status; + http->redirect.location = xstrdup(t+1); + } else { + debug(33,1)("clientRedirectDone: bad input: %s\n", result); + } + } + if (strcmp(result, http->uri)) + new_request = urlParse(old_request->method, result); + } if (new_request) { safe_free(http->uri); http->uri = xstrdup(urlCanonical(new_request)); @@ -656,6 +668,7 @@ httpRequestFree(void *data) safe_free(http->log_uri); safe_free(http->al.headers.request); safe_free(http->al.headers.reply); + safe_free(http->redirect.location); stringClean(&http->range_iter.boundary); if (entry) { http->entry = NULL; @@ -1800,6 +1813,15 @@ clientProcessMiss(clientHttpRequest * http) assert(http->out.offset == 0); http->entry = clientCreateStoreEntry(http, r->method, r->flags); http->entry->refcount++; + if (http->redirect.status) { + HttpReply *rep = httpReplyCreate(); + storeReleaseRequest(http->entry); + httpRedirectReply(rep, http->redirect.status, http->redirect.location); + httpReplySwapOut(rep, http->entry); + httpReplyDestroy(rep); + storeComplete(http->entry); + return; + } if (http->flags.internal) r->protocol = PROTO_INTERNAL; fwdStart(http->conn->fd, http->entry, r, http->conn->peer.sin_addr); diff --git a/src/protos.h b/src/protos.h index 66a5d4e7d4..33b5b55ebc 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.278 1998/10/14 21:12:01 wessels Exp $ + * $Id: protos.h,v 1.279 1998/10/15 23:40:06 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -445,6 +445,7 @@ extern int httpReplyContentLen(const HttpReply * rep); extern const char *httpReplyContentType(const HttpReply * rep); extern time_t httpReplyExpires(const HttpReply * rep); extern int httpReplyHasCc(const HttpReply * rep, http_hdr_cc_type type); +extern void httpRedirectReply(HttpReply *, http_status, const char *); /* Http Request */ extern request_t *requestCreate(method_t, protocol_t, const char *urlpath); diff --git a/src/structs.h b/src/structs.h index 4e77f34b9b..16d8c83b3b 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.241 1998/10/15 17:34:33 wessels Exp $ + * $Id: structs.h,v 1.242 1998/10/15 23:40:07 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -820,6 +820,10 @@ struct _clientHttpRequest { unsigned int internal:1; unsigned int done_copying:1; } flags; + struct { + http_status status; + char *location; + } redirect; }; struct _ConnStateData {