Skip to content
Browse files

Include a version on the end of the Ajax GUID.

AJAX requests currently carry a GUID. We now add a single-character
version indicator. This version increments for distinct AJAX requests.
In particular, it does NOT increment during AJAX retries, so that a
retry of an existing request can be identified as being part of the same
attempt on the server.

Not all AJAX requests carry this version identifier. In particular, Lift
GC requests do not carry a version identifier. This is because these
are going to be handled in a streamlined handler. If a Lift GC request
doesn't make it through, we can retry it as many times as we want and
it'll just remark stuff in the session.

liftAjax.addPageNameAndVersion appends both the page GUID and the
version number. The version number is encoded in base-36.
  • Loading branch information...
1 parent 4b61567 commit bbd703dcad3296e211354c9a521707c8f2fc0b31 @Shadowfiend Shadowfiend committed Aug 18, 2012
View
31 web/webkit/src/main/scala/net/liftweb/http/js/JSArtifacts.scala
@@ -112,24 +112,24 @@ trait JSArtifacts {
}
/**
- * The companion module for AjaxInfo that provides
+ * The companion module for AjaxInfodd that provides
* different construction schemes
*/
object AjaxInfo {
def apply(data: JsExp, post: Boolean) =
- new AjaxInfo(data, if (post) "POST" else "GET", 1000, false, "script", Empty, Empty)
+ new AjaxInfo(data, if (post) "POST" else "GET", 1000, false, "script", Empty, Empty, true)
def apply(data: JsExp,
dataType: String,
post: Boolean) =
- new AjaxInfo(data, if (post) "POST" else "GET", 1000, false, dataType, Empty, Empty)
+ new AjaxInfo(data, if (post) "POST" else "GET", 1000, false, dataType, Empty, Empty, true)
def apply(data: JsExp) =
- new AjaxInfo(data, "POST", 1000, false, "script", Empty, Empty)
+ new AjaxInfo(data, "POST", 1000, false, "script", Empty, Empty, true)
def apply(data: JsExp,
dataType: String) =
- new AjaxInfo(data, "POST", 1000, false, dataType, Empty, Empty)
+ new AjaxInfo(data, "POST", 1000, false, dataType, Empty, Empty, true)
def apply(data: JsExp,
post: Boolean,
@@ -142,13 +142,30 @@ object AjaxInfo {
false,
"script",
Full(successFunc),
- Full(failFunc))
+ Full(failFunc),
+ true)
+
+ def apply(data: JsExp,
+ post: Boolean,
+ timeout: Long,
+ successFunc: String,
+ failFunc: String,
+ includeVersion: Boolean) =
+ new AjaxInfo(data,
+ if (post) "POST" else "GET",
+ timeout,
+ false,
+ "script",
+ Full(successFunc),
+ Full(failFunc),
+ includeVersion)
}
/**
* Represents the meta data of an Ajax request.
*/
case class AjaxInfo(data: JsExp, action: String, timeout: Long,
cache: Boolean, dataType: String,
- successFunc: Box[String], failFunc: Box[String])
+ successFunc: Box[String], failFunc: Box[String],
+ includeVersion: Boolean)
View
23 web/webkit/src/main/scala/net/liftweb/http/js/ScriptRenderer.scala
@@ -107,8 +107,7 @@ object ScriptRenderer {
"POST",
LiftRules.ajaxPostTimeout,
false, "script",
- Full("liftAjax.lift_successRegisterGC"), Full("liftAjax.lift_failRegisterGC"))) +
- """
+ Full("liftAjax.lift_successRegisterGC"), Full("liftAjax.lift_failRegisterGC"), false)) + """
},
@@ -132,6 +131,7 @@ object ScriptRenderer {
aboutToSend.onSuccess(data);
}
liftAjax.lift_doCycleQueueCnt++;
+ liftAjax.lift_ajaxVersion++;
liftAjax.lift_doAjaxCycle();
};
@@ -145,6 +145,7 @@ object ScriptRenderer {
queue.push(aboutToSend);
liftAjax.lift_ajaxQueueSort();
} else {
+ liftAjax.lift_ajaxVersion++;
if (aboutToSend.onFailure) {
aboutToSend.onFailure();
} else {
@@ -180,6 +181,18 @@ object ScriptRenderer {
setTimeout("liftAjax.lift_doAjaxCycle();", 200);
},
+ lift_ajaxVersion: 0,
+
+ addPageNameAndVersion: function(url) {
+ return """ + {
+ if (LiftRules.enableLiftGC) {
+ "url.replace('" + LiftRules.ajaxPath + "', '" + LiftRules.ajaxPath + "/'+lift_page+(liftAjax.lift_ajaxVersion % 36).toString(36));"
+ } else {
+ "url;"
+ }
+ } + """
+ },
+
addPageName: function(url) {
return """ + {
if (LiftRules.enableLiftGC) {
@@ -196,7 +209,7 @@ object ScriptRenderer {
"POST",
LiftRules.ajaxPostTimeout,
false, "script",
- Full("onSuccess"), Full("onFailure"))) +
+ Full("onSuccess"), Full("onFailure"), true)) +
"""
},
@@ -206,7 +219,7 @@ object ScriptRenderer {
"POST",
LiftRules.ajaxPostTimeout,
false, "json",
- Full("onSuccess"), Full("onFailure"))) +
+ Full("onSuccess"), Full("onFailure"), true)) +
"""
}
};
@@ -279,7 +292,7 @@ object ScriptRenderer {
false,
"script",
Full("liftComet.lift_handlerSuccessFunc"),
- Full("liftComet.lift_handlerFailureFunc"))) +
+ Full("liftComet.lift_handlerFailureFunc"), false)) +
"""
}
}
View
2 web/webkit/src/main/scala/net/liftweb/http/js/extcore/ExtCoreArtifacts.scala
@@ -148,7 +148,7 @@ object ExtCoreArtifacts extends JSArtifacts {
}
private def toJson(info: AjaxInfo, server: String, path: String => JsExp): String =
- (("url : liftAjax.addPageName(" + path(server).toJsCmd + ")" ) ::
+ (("url : liftAjax.addPageNameAndVersion(" + path(server).toJsCmd + ")" ) ::
"params : " + info.data.toJsCmd ::
("method : " + info.action.encJs) ::
("dataType : " + info.dataType.encJs) ::
View
8 web/webkit/src/main/scala/net/liftweb/http/js/jquery/JQueryArtifacts.scala
@@ -95,9 +95,15 @@ trait JQueryArtifacts extends JSArtifacts {
* attributes described by data parameter
*/
def ajax(data: AjaxInfo): String = {
+ val versionIncluder =
+ if (data.includeVersion)
+ "liftAjax.addPageNameAndVersion"
+ else
+ "liftAjax.addPageName"
+
"jQuery.ajax(" + toJson(data, S.contextPath,
prefix =>
- JsRaw("liftAjax.addPageName(" + S.encodeURL(prefix + "/" + LiftRules.ajaxPath + "/").encJs + ")")) + ");"
+ JsRaw(versionIncluder + "(" + S.encodeURL(prefix + "/" + LiftRules.ajaxPath + "/").encJs + ")")) + ");"
}
/**
View
8 web/webkit/src/main/scala/net/liftweb/http/js/yui/YUIArtifacts.scala
@@ -126,9 +126,15 @@ object YUIArtifacts extends JSArtifacts {
* attributes described by data parameter
*/
def ajax(data: AjaxInfo): String = {
+ val versionIncluder =
+ if (data.includeVersion)
+ "liftAjax.addPageNameAndVersion"
+ else
+ "liftAjax.addPageName"
+
val url = S.encodeURL(S.contextPath + "/" + LiftRules.ajaxPath + "/")
- "url = YAHOO.lift.buildURI(liftAjax.addPageName(" + url.encJs + ") , " + data.data.toJsCmd + ");" +
+ "url = YAHOO.lift.buildURI(" + versionIncluder + "(" + url.encJs + ") , " + data.data.toJsCmd + ");" +
"YAHOO.util.Connect.asyncRequest(" + data.action.encJs + ", url, " + toJson(data) + ");"
}

0 comments on commit bbd703d

Please sign in to comment.
Something went wrong with that request. Please try again.