From rachelsimmons@example.net Wed Oct 08 20:59:05 2003
Return-Path: <rachelsimmons@example.net>
Delivered-To: rachelsimmons@example.net
Received: (qmail 92521 invoked from network); 8 Oct 2003 20:59:05 -0000
Received: from daedalus.apache.org (HELO mail.apache.org) (83.161.120.155)
  by minotaur-2.apache.org with SMTP; 8 Oct 2003 20:59:05 -0000
Received: (qmail 23613 invoked by uid 500); 8 Oct 2003 20:58:49 -0000
Delivered-To: rachelsimmons@example.net
Received: (qmail 23506 invoked by uid 500); 8 Oct 2003 20:58:48 -0000
Mailing-List: contact rachelsimmons@example.net; run by ezmlm
Precedence: bulk
List-Post: <mailto:rachelsimmons@example.net>
List-Help: <mailto:rachelsimmons@example.net>
List-Unsubscribe: <mailto:rachelsimmons@example.net>
List-Subscribe: <mailto:rachelsimmons@example.net>
Delivered-To: mailing list rachelsimmons@example.net
Received: (qmail 23407 invoked from network); 8 Oct 2003 20:58:47 -0000
Received: from unknown (HELO kaiserslautern1.lms-gmbh.de) (83.161.120.155)
  by daedalus.apache.org with SMTP; 8 Oct 2003 20:58:47 -0000
Received: by kaiserslautern1.lms-gmbh.de with Internet Mail Service (5.5.2653.19)
	id <SW2AGDHF>; Wed, 8 Oct 2003 22:58:52 +0200
Message-ID: <rachelsimmons@example.net>
From: "Zeinert, Holger" <rachelsimmons@example.net>
To: rachelsimmons@example.net, rachelsimmons@example.net
Subject: setting a permanent cookie
Date: Wed, 8 Oct 2003 22:58:51 +0200 
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N

Hi,

since some time I was trying to set a cookie in mod_dtcl. Session =
cookies
were no problem:

  headers setcookie -name "Foo" -value "Bar"

I guess it's very similar in Rivet.

But to save a permanent cookie, a expire date is needed. I tried =
several
common formats like

	Wed Oct 08 22:36:19 Westeurop=E4ische Sommerzeit 2003
	DD-Mon-YY HH:MM:SS
	...

but I had no success. As soon as the expire was set, the whole cookie =
was
lost. I should add that this happens only with Microsoft Internet =
Explorer
6.0.

After reading the sources of mod_dtcl and Apache I think I discovered =
the
following:

the expire date seems to be set relativ, starting with "+" or "-".

apache_request.c:

char *ApacheUtil_expires(pool *p, char *time_str, int type)
{
    ...
    when =3D expire_calc(time_str);
    ...
}

static time_t expire_calc(char *time_str)
{
    int is_neg =3D 0, offset =3D 0;
    char buf[256];
    int ix =3D 0;

    if (*time_str =3D=3D '-') {
	is_neg =3D 1;
	++time_str;
    }=20
    else if (*time_str =3D=3D '+') {
	++time_str;
    }
    else if (strcaseEQ(time_str, "now")) {
	/*ok*/
    }
    else {
	return 0;
    }

    /* wtf, ap_isdigit() returns false for '1' !? */
    while (*time_str && (ap_isdigit(*time_str) || (*time_str =3D=3D =
'1'))) {
	buf[ix++] =3D *time_str++;
    }
    buf[ix] =3D '\0';
    offset =3D atoi(buf);

    return time(NULL) +=20
	(expire_mult(*time_str) * (is_neg ? (0 - offset) : offset));
}

#define Mult_s 1
#define Mult_m 60
#define Mult_h (60*60)
#define Mult_d (60*60*24)
#define Mult_M (60*60*24*30)
#define Mult_y (60*60*24*365)

static int expire_mult(char s)
{
    switch (s) {
    case 's':
	return Mult_s;
    case 'm':
	return Mult_m;
    case 'h':
	return Mult_h;
    case 'd':
	return Mult_d;
    case 'M':
	return Mult_M;
    case 'y':
	return Mult_y;
    default:
	return 1;
    };
}

The first if-elseif statement in expire_calc() returns 0 if the =
time_str
does not start with + or - nor is equal to "now".
Also, the value from time_str is used as offset.

Conclusion: setting a permanent cookie (at least with Internet =
Explorer)
works using expires like "+1d", "+2min", ...

    header setcookie -name "Foo" -value "Bar" -expires "+[expr =
24*60*60]"
or
    header setcookie -name "Foo" -value "Bar" -expires "+1d"=20

to make the cookie permanent, expiring one day later.

Although this works for me, I would like to hear comments on that. But =
since
this code is in the http server, it should not depend on the Browser, =
right?
Is my conclusion correct? I did not find much documentation about how =
to
format expire values for cookies.

Best regards
Holger

---------------------------------------------------------------------
To unsubscribe, e-mail: rachelsimmons@example.net
For additional commands, e-mail: rachelsimmons@example.net



{'source': 'Apache Software Foundation Public Mail Archives'}