You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/06/22 02:19:13 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util CookieTools.java
craigmcc 00/06/21 17:19:13
Modified: proposals/catalina/src/conf server.xml
proposals/catalina/src/share/org/apache/tomcat/connector
HttpRequestBase.java HttpResponseBase.java
proposals/catalina/src/share/org/apache/tomcat/connector/http
HttpProcessor.java
proposals/catalina/src/share/org/apache/tomcat/connector/test
HttpProcessor.java
proposals/catalina/src/share/org/apache/tomcat/core
ApplicationDispatcher.java
proposals/catalina/src/share/org/apache/tomcat/session
StandardSession.java
Added: proposals/catalina/src/share/org/apache/tomcat/util
CookieTools.java
Log:
Clean up session management where cookies are used. This should now work
correctly, along with URL-rewriting based sessions which continue to work.
When parsing HTTP headers, store the received headers even if they are
special ones like "Content-Length" or "Content-Type". Some existing
applications rely on these headers being visible.
When session.access() is called, also set isNew to false so that sessions
will not appear to be new forever.
Switch to the HTTP/1.1 connector implementation as the default.
Revision Changes Path
1.35 +2 -2 jakarta-tomcat/proposals/catalina/src/conf/server.xml
Index: server.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/conf/server.xml,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- server.xml 2000/06/12 20:18:38 1.34
+++ server.xml 2000/06/22 00:19:01 1.35
@@ -6,15 +6,15 @@
<!-- Define all the connectors to associate with the following container -->
-<!--
<Connector className="org.apache.tomcat.connector.http.HttpConnector"
port="8080" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>
--->
+<!--
<Connector className="org.apache.tomcat.connector.test.HttpConnector"
port="8080" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>
+-->
<!-- Define the top level container in our container hierarchy -->
1.11 +7 -5 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java
Index: HttpRequestBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HttpRequestBase.java 2000/05/30 21:29:43 1.10
+++ HttpRequestBase.java 2000/06/22 00:19:02 1.11
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v 1.10 2000/05/30 21:29:43 craigmcc Exp $
- * $Revision: 1.10 $
- * $Date: 2000/05/30 21:29:43 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v 1.11 2000/06/22 00:19:02 craigmcc Exp $
+ * $Revision: 1.11 $
+ * $Date: 2000/06/22 00:19:02 $
*
* ====================================================================
*
@@ -93,7 +93,7 @@
* be implemented.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.10 $ $Date: 2000/05/30 21:29:43 $
+ * @version $Revision: 1.11 $ $Date: 2000/06/22 00:19:02 $
*/
public class HttpRequestBase
@@ -902,8 +902,10 @@
}
if ((session != null) && !session.isValid())
session = null;
- if (session != null)
+ if (session != null) {
+ session.access();
return (session.getSession());
+ }
}
// Create a new session if requested
1.10 +12 -11 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java
Index: HttpResponseBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HttpResponseBase.java 2000/05/30 21:29:43 1.9
+++ HttpResponseBase.java 2000/06/22 00:19:03 1.10
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v 1.9 2000/05/30 21:29:43 craigmcc Exp $
- * $Revision: 1.9 $
- * $Date: 2000/05/30 21:29:43 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v 1.10 2000/06/22 00:19:03 craigmcc Exp $
+ * $Revision: 1.10 $
+ * $Date: 2000/06/22 00:19:03 $
*
* ====================================================================
*
@@ -83,6 +83,7 @@
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUtils;
import org.apache.tomcat.HttpResponse;
+import org.apache.tomcat.util.CookieTools;
import org.apache.tomcat.util.RequestUtil;
@@ -93,7 +94,7 @@
* methods need to be implemented.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2000/05/30 21:29:43 $
+ * @version $Revision: 1.10 $ $Date: 2000/06/22 00:19:03 $
*/
public class HttpResponseBase
@@ -455,11 +456,10 @@
}
// Add the session ID cookie if necessary
- // FIXME - if we used to have a session, expire the old cookie?
HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
HttpSession session = hreq.getSession(false);
- if ((session != null) && session.isNew() &&
- !hreq.isRequestedSessionIdFromURL()) {
+
+ if ((session != null) && session.isNew()) {
Cookie cookie = new Cookie(Constants.SessionCookie,
session.getId());
cookie.setMaxAge(-1);
@@ -468,7 +468,6 @@
cookie.setPath(contextPath);
if (hreq.isSecure())
cookie.setSecure(true);
- cookie.setVersion(1);
addCookie(cookie);
}
@@ -476,10 +475,12 @@
Enumeration items = cookies.elements();
while (items.hasMoreElements()) {
Cookie cookie = (Cookie) items.nextElement();
- outputWriter.print("Set-Cookie: ");
- outputWriter.print(RequestUtil.encodeCookie(cookie));
+ outputWriter.print(CookieTools.getCookieHeaderName(cookie));
+ outputWriter.print(": ");
+ outputWriter.print(CookieTools.getCookieHeaderValue(cookie));
outputWriter.print("\r\n");
-// log(" Set-Cookie: " + RequestUtil.encodeCookie(cookie));
+ // log(" " + CookieTools.getCookieHeaderName(cookie) + ": " +
+ // CookieTools.getCookieHeaderValue(cookie));
}
// Send a terminating blank line to mark the end of the headers
1.14 +7 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java
Index: HttpProcessor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HttpProcessor.java 2000/06/01 05:37:31 1.13
+++ HttpProcessor.java 2000/06/22 00:19:05 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java,v 1.13 2000/06/01 05:37:31 remm Exp $
- * $Revision: 1.13 $
- * $Date: 2000/06/01 05:37:31 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpProcessor.java,v 1.14 2000/06/22 00:19:05 craigmcc Exp $
+ * $Revision: 1.14 $
+ * $Date: 2000/06/22 00:19:05 $
*
* ====================================================================
*
@@ -104,7 +104,7 @@
*
* @author Craig R. McClanahan
* @author Remy Maucherat
- * @version $Revision: 1.13 $ $Date: 2000/06/01 05:37:31 $
+ * @version $Revision: 1.14 $ $Date: 2000/06/22 00:19:05 $
*/
final class HttpProcessor
@@ -498,8 +498,10 @@
("httpProcessor.parseHeaders.contentLength"));
}
request.setContentLength(n);
+ request.addHeader(name, value);
} else if (match.equals("content-type")) {
request.setContentType(value);
+ request.addHeader(name, value);
} else if (match.equals("host")) {
int n = value.indexOf(":");
if (n < 0)
@@ -516,6 +518,7 @@
}
request.setServerPort(port);
}
+ request.addHeader(name, value);
} else if (match.equals("connection")) {
if ("close".equalsIgnoreCase(value)) {
keepAlive = false;
1.14 +7 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/test/HttpProcessor.java
Index: HttpProcessor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/test/HttpProcessor.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HttpProcessor.java 2000/05/31 18:56:07 1.13
+++ HttpProcessor.java 2000/06/22 00:19:06 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/test/HttpProcessor.java,v 1.13 2000/05/31 18:56:07 craigmcc Exp $
- * $Revision: 1.13 $
- * $Date: 2000/05/31 18:56:07 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/test/HttpProcessor.java,v 1.14 2000/06/22 00:19:06 craigmcc Exp $
+ * $Revision: 1.14 $
+ * $Date: 2000/06/22 00:19:06 $
*
* ====================================================================
*
@@ -103,7 +103,7 @@
* the request. When the processor is completed, it will recycle itself.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.13 $ $Date: 2000/05/31 18:56:07 $
+ * @version $Revision: 1.14 $ $Date: 2000/06/22 00:19:06 $
*/
final class HttpProcessor
@@ -459,8 +459,10 @@
(sm.getString("httpProcessor.parseHeaders.contentLength"));
}
request.setContentLength(n);
+ request.addHeader(name, value);
} else if (match.equals("content-type")) {
request.setContentType(value);
+ request.addHeader(name, value);
} else if (match.equals("host")) {
int n = value.indexOf(":");
if (n < 0)
@@ -476,6 +478,7 @@
}
request.setServerPort(port);
}
+ request.addHeader(name, value);
} else {
request.addHeader(name, value);
}
1.6 +5 -5 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java
Index: ApplicationDispatcher.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ApplicationDispatcher.java 2000/06/19 21:46:49 1.5
+++ ApplicationDispatcher.java 2000/06/22 00:19:08 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v 1.5 2000/06/19 21:46:49 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2000/06/19 21:46:49 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v 1.6 2000/06/22 00:19:08 craigmcc Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/06/22 00:19:08 $
*
* ====================================================================
*
@@ -93,7 +93,7 @@
* from this resource.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2000/06/19 21:46:49 $
+ * @version $Revision: 1.6 $ $Date: 2000/06/22 00:19:08 $
*/
final class ApplicationDispatcher
@@ -145,7 +145,7 @@
/**
* The debugging detail level for this component.
*/
- private int debug = 2;
+ private int debug = 0;
/**
1.8 +5 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/StandardSession.java
Index: StandardSession.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/StandardSession.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- StandardSession.java 2000/06/21 22:37:27 1.7
+++ StandardSession.java 2000/06/22 00:19:10 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/StandardSession.java,v 1.7 2000/06/21 22:37:27 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/06/21 22:37:27 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/session/StandardSession.java,v 1.8 2000/06/22 00:19:10 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/06/22 00:19:10 $
*
* ====================================================================
*
@@ -101,7 +101,7 @@
*
* @author Craig R. McClanahan
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Revision: 1.7 $ $Date: 2000/06/21 22:37:27 $
+ * @version $Revision: 1.8 $ $Date: 2000/06/22 00:19:10 $
*/
final class StandardSession
@@ -397,6 +397,7 @@
*/
public void access() {
+ this.isNew = false;
this.lastAccessedTime = this.thisAccessedTime;
this.thisAccessedTime = System.currentTimeMillis();
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/CookieTools.java
Index: CookieTools.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/CookieTools.java,v 1.1 2000/06/22 00:19:12 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/06/22 00:19:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.util;
import java.text.*;
import java.util.*;
import javax.servlet.http.Cookie;
// XXX use only one Date instance/request, reuse it.
/**
* Cookie utils - generate cookie header, etc
*
* @author Original Author Unknown
* @author duncan@eng.sun.com
*/
public class CookieTools {
/** Return the header name to set the cookie, based on cookie
* version
*/
public static String getCookieHeaderName(Cookie cookie) {
int version = cookie.getVersion();
if (version == 1) {
return "Set-Cookie2";
} else {
return "Set-Cookie";
}
}
/** Return the header value used to set this cookie
* @deprecated Use StringBuffer version
*/
public static String getCookieHeaderValue(Cookie cookie) {
StringBuffer buf = new StringBuffer();
getCookieHeaderValue( cookie, buf );
return buf.toString();
}
/** Return the header value used to set this cookie
*/
public static void getCookieHeaderValue(Cookie cookie, StringBuffer buf) {
int version = cookie.getVersion();
// this part is the same for all cookies
buf.append(cookie.getName());
buf.append("=");
maybeQuote(version, buf, cookie.getValue());
// add version 1 specific information
if (version == 1) {
// Version=1 ... required
buf.append (";Version=1");
// Comment=comment
if (cookie.getComment() != null) {
buf.append (";Comment=");
maybeQuote (version, buf, cookie.getComment());
}
}
// add domain information, if present
if (cookie.getDomain() != null) {
buf.append(";Domain=");
maybeQuote (version, buf, cookie.getDomain());
}
// Max-Age=secs/Discard ... or use old "Expires" format
if (cookie.getMaxAge() >= 0) {
if (version == 0) {
buf.append (";Expires=");
DateTool.oldCookieFormat.format(new Date( System.currentTimeMillis() + cookie.getMaxAge() *1000) ,buf,
new FieldPosition(0));
} else {
buf.append (";Max-Age=");
buf.append (cookie.getMaxAge());
}
} else if (version == 1)
buf.append (";Discard");
// Path=path
if (cookie.getPath() != null) {
buf.append (";Path=");
maybeQuote (version, buf, cookie.getPath());
}
// Secure
if (cookie.getSecure()) {
buf.append (";Secure");
}
}
static void maybeQuote (int version, StringBuffer buf,
String value)
{
if (version == 0 || isToken (value))
buf.append (value);
else {
buf.append ('"');
buf.append (value);
buf.append ('"');
}
}
//
// from RFC 2068, token special case characters
//
private static final String tspecials = "()<>@,;:\\\"/[]?={} \t";
/*
* Return true iff the string counts as an HTTP/1.1 "token".
*/
private static boolean isToken (String value) {
int len = value.length ();
for (int i = 0; i < len; i++) {
char c = value.charAt (i);
if (c < 0x20 || c >= 0x7f || tspecials.indexOf (c) != -1)
return false;
}
return true;
}
}