Mercurial > urweb
comparison lib/js/urweb.js @ 736:796e42c93c48
Cookie signatures for RPCs
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 23 Apr 2009 16:13:02 -0400 |
parents | 7c6b6c3c7b79 |
children | 2c463eee89fa |
comparison
equal
deleted
inserted
replaced
735:5ccb67665d05 | 736:796e42c93c48 |
---|---|
351 } | 351 } |
352 } | 352 } |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 function requestUri(xhr, uri) { | 356 var sig = null; |
357 | |
358 function requestUri(xhr, uri, needsSig) { | |
357 xhr.open("GET", uri, true); | 359 xhr.open("GET", uri, true); |
358 | 360 |
359 if (client_id != null) { | 361 if (client_id != null) { |
360 xhr.setRequestHeader("UrWeb-Client", client_id.toString()); | 362 xhr.setRequestHeader("UrWeb-Client", client_id.toString()); |
361 xhr.setRequestHeader("UrWeb-Pass", client_pass.toString()); | 363 xhr.setRequestHeader("UrWeb-Pass", client_pass.toString()); |
362 } | 364 } |
363 | 365 |
366 if (needsSig) { | |
367 if (sig == null) | |
368 whine("Missing cookie signature!"); | |
369 | |
370 xhr.setRequestHeader("UrWeb-Sig", sig); | |
371 } | |
372 | |
364 xhr.send(null); | 373 xhr.send(null); |
365 } | 374 } |
366 | 375 |
367 function rc(uri, parse, k) { | 376 function rc(uri, parse, k, needsSig) { |
368 uri = flattenLocal(uri); | 377 uri = flattenLocal(uri); |
369 var xhr = getXHR(); | 378 var xhr = getXHR(); |
370 | 379 |
371 xhr.onreadystatechange = function() { | 380 xhr.onreadystatechange = function() { |
372 if (xhr.readyState == 4) { | 381 if (xhr.readyState == 4) { |
387 conn(); | 396 conn(); |
388 } | 397 } |
389 } | 398 } |
390 }; | 399 }; |
391 | 400 |
392 requestUri(xhr, uri); | 401 requestUri(xhr, uri, needsSig); |
393 } | 402 } |
394 | 403 |
395 function path_join(s1, s2) { | 404 function path_join(s1, s2) { |
396 if (s1.length > 0 && s1[s1.length-1] == '/') | 405 if (s1.length > 0 && s1[s1.length-1] == '/') |
397 return s1 + s2; | 406 return s1 + s2; |
436 var tid, orsc, onTimeout; | 445 var tid, orsc, onTimeout; |
437 | 446 |
438 var connect = function () { | 447 var connect = function () { |
439 xhr.onreadystatechange = orsc; | 448 xhr.onreadystatechange = orsc; |
440 tid = window.setTimeout(onTimeout, timeout * 500); | 449 tid = window.setTimeout(onTimeout, timeout * 500); |
441 requestUri(xhr, uri); | 450 requestUri(xhr, uri, false); |
442 } | 451 } |
443 | 452 |
444 orsc = function() { | 453 orsc = function() { |
445 if (xhr.readyState == 4) { | 454 if (xhr.readyState == 4) { |
446 window.clearTimeout(tid); | 455 window.clearTimeout(tid); |
488 | 497 |
489 connect(); | 498 connect(); |
490 } | 499 } |
491 else { | 500 else { |
492 try { | 501 try { |
493 servError("Error querying remote server for messages: " + xhr.status); | 502 servErr("Error querying remote server for messages: " + xhr.status); |
494 } catch (e) { servError("Error querying remote server for messages"); } | 503 } catch (e) { servErr("Error querying remote server for messages"); } |
495 } | 504 } |
496 } | 505 } |
497 }; | 506 }; |
498 | 507 |
499 onTimeout = function() { | 508 onTimeout = function() { |