From 0eb174ae527f5e08126ae7f99742589d3cd6ab6b Mon Sep 17 00:00:00 2001 From: Ian Holsman Date: Thu, 29 Aug 2002 22:45:13 +0000 Subject: [PATCH] set expiry time correctly. set Cookie on err_headers_out, and ensure it is only set once. PR: 12132 Submitted by: apachecvslog@robcromwell.com (Rob Cromwell) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96577 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 +++ modules/mappers/mod_rewrite.c | 55 ++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index bb3159dc93..cc00f63c74 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Changes with Apache 2.0.41 + *) mod_rewrite can now sets cookies in err_headers, and uses the correct + expiry date. PR 12132 + [Ian Holsman / Rob Cromwell ] + *) The content-length filter no longer tries to buffer up the entire output of a long-running request before sending anything to the client. [Brian Pane] diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 0e2d014f36..16e01e19a4 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -4147,27 +4147,42 @@ static void add_cookie(request_rec *r, char *s) if (var && val && domain) { /* FIX: use cached time similar to how logging does it */ - cookie = apr_pstrcat( r->pool, - var, - "=", - val, - "; path=/; domain=", - domain, - (expires)? "; expires=" : NULL, - (expires)? ap_ht_time(r->pool, - r->request_time + - (60 * atol(expires)), - "%a, %d-%b-%Y %T GMT", 1) - : NULL, - NULL); - + request_rec *rmain = r; + char *notename; + char *data; + while (rmain->main) { + rmain = rmain->main; + } - /* - * XXX: should we add it to err_headers_out as well ? - * if we do we need to be careful that only ONE gets sent out - */ - apr_table_add(r->headers_out, "Set-Cookie", cookie); - rewritelog(r, 5, "setting cookie '%s' to '%s'", var, val); + notename = apr_pstrcat(rmain->pool, var, "_rewrite", NULL); + apr_pool_userdata_get( &data, notename, rmain->pool); + if (data== NULL) { + cookie = apr_pstrcat(rmain->pool, + var, + "=", + val, + "; path=/; domain=", + domain, + (expires)? "; expires=" : NULL, + (expires)? + ap_ht_time(r->pool, + r->request_time + + apr_time_from_sec((60 * + atol(expires))), + "%a, %d-%b-%Y %T GMT", 1) + : NULL, + NULL); + /* + * XXX: should we add it to err_headers_out as well ? + * if we do we need to be careful that only ONE gets sent out + */ + apr_table_add(rmain->err_headers_out, "Set-Cookie", cookie); + apr_pool_userdata_set("set", notename, NULL, rmain->pool); + rewritelog(rmain, 5, "setting cookie '%s' to '%s'", var, val); + } + else { + rewritelog(rmain, 5, "cookie '%s' is already set..skipping", var); + } } } } -- 2.40.0