Mercurial > urweb
comparison lib/js/urweb.js @ 1691:ea292bf9431f
Avoid URL size limit in RPCs with large arguments
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sat, 03 Mar 2012 16:41:20 -0500 |
parents | 225b87d4a7df |
children | 06791667937e |
comparison
equal
deleted
inserted
replaced
1690:a7b70c7b3f1a | 1691:ea292bf9431f |
---|---|
1135 for (; inFlight; inFlight = inFlight.next) { | 1135 for (; inFlight; inFlight = inFlight.next) { |
1136 inFlight.data.abort(); | 1136 inFlight.data.abort(); |
1137 } | 1137 } |
1138 } | 1138 } |
1139 | 1139 |
1140 function requestUri(xhr, uri, needsSig) { | 1140 function requestUri(xhr, uri, needsSig, isRpc) { |
1141 if (unloading) | 1141 if (unloading) |
1142 return; | 1142 return; |
1143 | |
1144 var extraData = null; | |
1145 | |
1146 if (isRpc && uri.length > 2000) { | |
1147 extraData = uri.substring(2000); | |
1148 uri = uri.substring(0, 2000); | |
1149 } | |
1143 | 1150 |
1144 xhr.open("POST", uri, true); | 1151 xhr.open("POST", uri, true); |
1145 xhr.setRequestHeader("Content-type", "text/plain"); | 1152 xhr.setRequestHeader("Content-type", "text/plain"); |
1146 try { | 1153 try { |
1147 xhr.setRequestHeader("Content-length", "0"); | 1154 xhr.setRequestHeader("Content-length", "0"); |
1159 | 1166 |
1160 xhr.setRequestHeader("UrWeb-Sig", sig); | 1167 xhr.setRequestHeader("UrWeb-Sig", sig); |
1161 } | 1168 } |
1162 | 1169 |
1163 inFlight = cons(xhr, inFlight); | 1170 inFlight = cons(xhr, inFlight); |
1164 xhr.send(null); | 1171 xhr.send(extraData); |
1165 } | 1172 } |
1166 | 1173 |
1167 function xhrFinished(xhr) { | 1174 function xhrFinished(xhr) { |
1168 xhr.abort(); | 1175 xhr.abort(); |
1169 inFlight = remove(xhr, inFlight); | 1176 inFlight = remove(xhr, inFlight); |
1209 | 1216 |
1210 xhrFinished(xhr); | 1217 xhrFinished(xhr); |
1211 } | 1218 } |
1212 }; | 1219 }; |
1213 | 1220 |
1214 requestUri(xhr, uri, needsSig); | 1221 requestUri(xhr, uri, needsSig, true); |
1215 } | 1222 } |
1216 | 1223 |
1217 function path_join(s1, s2) { | 1224 function path_join(s1, s2) { |
1218 if (s1.length > 0 && s1.charAt(s1.length-1) == '/') | 1225 if (s1.length > 0 && s1.charAt(s1.length-1) == '/') |
1219 return s1 + s2; | 1226 return s1 + s2; |
1258 var tid, orsc, onTimeout; | 1265 var tid, orsc, onTimeout; |
1259 | 1266 |
1260 var connect = function () { | 1267 var connect = function () { |
1261 xhr.onreadystatechange = orsc; | 1268 xhr.onreadystatechange = orsc; |
1262 tid = window.setTimeout(onTimeout, timeout * 500); | 1269 tid = window.setTimeout(onTimeout, timeout * 500); |
1263 requestUri(xhr, uri, false); | 1270 requestUri(xhr, uri, false, false); |
1264 } | 1271 } |
1265 | 1272 |
1266 orsc = function() { | 1273 orsc = function() { |
1267 if (xhr.readyState == 4) { | 1274 if (xhr.readyState == 4) { |
1268 window.clearTimeout(tid); | 1275 window.clearTimeout(tid); |