@Override
public WOSession createSessionForRequest(WORequest request) {
String userAgent = request.headerForKey("user-agent");
WOSession session = null;
if (userAgent != null && userAgent.toLowerCase().contains(“googlebot")) {
session = super.sessionStore().checkOutSessionWithID(sessionIDForRobots, request);
if (session == null) {
session = super.createSessionForRequest(request);
session.setStoresIDsInCookies(true);
session.setStoresIDsInURLs(false); //this means any urls generated for bots will be without the session id
sessionIDForRobots = session.sessionID();
log.debug("NEW SESSION CREATED FROM " + SHWORequestUtilities.clientIP(request) + " (" + userAgent + ")");
} else {
// no session created, so we need to "fix" the activeSessionsCount, which is incremented on every call to this method
ERXKeyValueCodingUtilities.takePrivateValueForKey(this, activeSessionsCount() - 1, "_activeSessionsCount");
}
log.debug("Known bot hitting application. User-Agent: " + userAgent);
} else {
session = super.createSessionForRequest(request);
log.debug("NEW SESSION CREATED FROM " + SHWORequestUtilities.clientIP(request) + " (" + userAgent + ")");
}
return session;
}
The only oddity is the when we’re checking out an existing session (bots), the session count goes up even though no session is created. I don’t remember where I got that bit of code. :) This has been in production for a long time and hasn’t caused us any problems, but your mileage may vary.