]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
support 301: 302: redirector hacks
authorwessels <>
Fri, 16 Oct 1998 05:40:04 +0000 (05:40 +0000)
committerwessels <>
Fri, 16 Oct 1998 05:40:04 +0000 (05:40 +0000)
src/HttpReply.cc
src/client_side.cc
src/protos.h
src/structs.h

index f75067647e936a49481ec2f9267e0278287a3d1f..4ad933b7e511a119d47d88b398b061c7a0e68610 100644 (file)
@@ -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)
 {
index c6d149e9f923465d6687c9c4f0d65ac607ab834d..879bdf6be3bd72165eb288eaea9156b98a80f39a 100644 (file)
@@ -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);
index 66a5d4e7d41c701b41b7e41676ddb2046e14a14d..33b5b55ebca8eb6086fb2d668cf0f966f4fb6102 100644 (file)
@@ -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);
index 4e77f34b9b53c3778cda4e3df120f4a7e1183cbb..16d8c83b3b2aacd058101192a93b5453a3e4d930 100644 (file)
@@ -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 {