From c80b5615c830b26fd10dca5564b25dad98628b8b Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 14 Oct 2003 02:00:45 +0000 Subject: [PATCH] Added widenDomain(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1266 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/servlet/util/CookieUtil.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/servlet/util/CookieUtil.java b/projects/samskivert/src/java/com/samskivert/servlet/util/CookieUtil.java index 86896913..17a81806 100644 --- a/projects/samskivert/src/java/com/samskivert/servlet/util/CookieUtil.java +++ b/projects/samskivert/src/java/com/samskivert/servlet/util/CookieUtil.java @@ -1,5 +1,5 @@ // -// $Id: CookieUtil.java,v 1.2 2003/10/09 00:48:37 ray Exp $ +// $Id: CookieUtil.java,v 1.3 2003/10/14 02:00:45 mdb Exp $ package com.samskivert.servlet.util; @@ -49,4 +49,20 @@ public class CookieUtil c.setMaxAge(0); rsp.addCookie(c); } + + /** + * Sets the domain of the specified cookie to the server name + * associated with the supplied request minus the hostname + * (ie. www.samskivert.com becomes + * .samskivert.com). + */ + public static void widenDomain (HttpServletRequest req, Cookie cookie) + { + String domain = req.getServerName(); + int didx = domain.indexOf("."); + if (didx != -1) { + domain = domain.substring(didx); + } + cookie.setDomain(domain); + } }