/*
- * $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
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)
{
/*
- * $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
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));
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;
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);
/*
- * $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/
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);