Author: jleroux
Date: Mon Jun 25 20:56:42 2007
New Revision: 550673
URL: http://svn.apache.org/viewvc?view=rev&rev=550673
Log:
A patch from Dimitri Unruh "Remove sessionid for Googlebot & Co."
(https://issues.apache.org/jira/browse/OFBIZ-857).
Modified:
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
ofbiz/trunk/framework/webapp/config/url.properties
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?view=diff&rev=550673&r1=550672&r2=550673
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
(original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Mon
Jun 25 20:56:42 2007
@@ -43,6 +43,8 @@
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -1040,5 +1042,42 @@
HttpSession session = request.getSession();
return (session == null ? "unknown" : session.getId());
}
-
+ /**
+ * checks, if the current request comes from a searchbot
+ *
+ * @param request
+ * @return
+ */
+ public static boolean checkURLforSpiders(HttpServletRequest request){
+ boolean result = false;
+
+ String spiderRequest = (String)
request.getAttribute("_REQUEST_FROM_SPIDER_");
+ if (UtilValidate.isNotEmpty(spiderRequest)){
+ if ("Y".equals(spiderRequest)){
+ return true;
+ }else{
+ return false;
+ }
+ }else{
+ String initialUserAgent = request.getHeader("User-Agent") != null
? request.getHeader("User-Agent") : "";
+ List spiderList =
StringUtil.split(UtilProperties.getPropertyValue("url",
"link.remove_lsessionid.user_agent_list"), ",");
+ Iterator spiderListIter = spiderList.iterator();
+ while (spiderListIter.hasNext()) {
+ String spiderNameElement = (String) spiderListIter.next();
+ Pattern p = Pattern.compile("^.*" + spiderNameElement + ".*$",
Pattern.CASE_INSENSITIVE);
+ Matcher m = p.matcher(initialUserAgent);
+ if (m.find()){
+ request.setAttribute("_REQUEST_FROM_SPIDER_", "Y");
+ result = true;
+ break;
+ }
+ }
+ }
+
+ if (!result)
+ request.setAttribute("_REQUEST_FROM_SPIDER_", "N");
+
+ return result;
+ }
+
}
Modified: ofbiz/trunk/framework/webapp/config/url.properties
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/url.properties?view=diff&rev=550673&r1=550672&r2=550673
==============================================================================
--- ofbiz/trunk/framework/webapp/config/url.properties (original)
+++ ofbiz/trunk/framework/webapp/config/url.properties Mon Jun 25 20:56:42 2007
@@ -22,11 +22,11 @@
# HTTPS Port (Secure port)
port.https.enabled=Y
-port.https=8443
+port.https=28443
force.https.host=
# HTTP Port (Not Secure port)
-port.http=8080
+port.http=28080
force.http.host=
# Static Content URLs to make it easy to move the serving load for static
content to other machines
@@ -36,3 +36,6 @@
# Here you can set the domain string to use for new cookies
cookie.domain=
+
+# Exclude jsessionid for User-Agents (separated by comma's)
+link.remove_lsessionid.user_agent_list = googlebot,yahoo,msnbot
Modified:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?view=diff&rev=550673&r1=550672&r2=550673
==============================================================================
---
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
(original)
+++
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
Mon Jun 25 20:56:42 2007
@@ -805,7 +805,13 @@
String encodedUrl;
if (encode) {
boolean forceManualJsessionid = false;
-
+ boolean isSpider = false;
+
+ // if the current request comes from a spider, we will not add the
jsessionid to the link
+ if (UtilHttp.checkURLforSpiders(request)){
+ isSpider = true;
+ }
+
// if this isn't a secure page, but we made a secure URL, make
sure we manually add the jsessionid since the response.encodeURL won't do that
if (!request.isSecure() && didFullSecure) {
forceManualJsessionid = true;
@@ -816,16 +822,18 @@
forceManualJsessionid = true;
}
- if (response != null && !forceManualJsessionid) {
+ if (response != null && !forceManualJsessionid && !isSpider) {
encodedUrl = response.encodeURL(newURL.toString());
} else {
- String sessionId = ";jsessionid=" +
request.getSession().getId();
- // this should be inserted just after the "?" for the
parameters, if there is one, or at the end of the string
- int questionIndex = newURL.indexOf("?");
- if (questionIndex == -1) {
- newURL.append(sessionId);
- } else {
- newURL.insert(questionIndex, sessionId);
+ if (!isSpider){
+ String sessionId = ";jsessionid=" +
request.getSession().getId();
+ // this should be inserted just after the "?" for the
parameters, if there is one, or at the end of the string
+ int questionIndex = newURL.indexOf("?");
+ if (questionIndex == -1) {
+ newURL.append(sessionId);
+ } else {
+ newURL.insert(questionIndex, sessionId);
+ }
}
encodedUrl = newURL.toString();
}