PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/WCFWebApi/src/Microsoft.ApplicationServer.Http/Microsoft/ApplicationServer/Http/Test/proxy.js

#
JavaScript | 98 lines | 82 code | 16 blank | 0 comment | 2 complexity | a69f353e95d1ca8a36ef398f39e4ff65 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. var proxy = {
  2. baseAddress: ""
  3. };
  4. proxy.postText = function (url, fullText, callback) {
  5. window.status = "sending request to server ...";
  6. var jqxhr = $.post(url, fullText, function (data) {
  7. window.status = "";
  8. callback(data);
  9. });
  10. jqxhr.error(function () {
  11. window.status = jqxhr.statusText; // +":" + jqxhr.responseText;
  12. });
  13. }
  14. proxy.postUriText = function (uriTemplate, httpMethod, curPos, fullText, callback) {
  15. var url = "request/uri?uri=" + encodeURIComponent(uriTemplate) + "&method=" + encodeURIComponent(httpMethod) + "&op=autocomplete" + "&cursorpos=" + curPos;
  16. return this.postText(url, fullText, callback);
  17. };
  18. proxy.postHeaderText = function (curPos, fullText, callback) {
  19. var url = "request/headers?cursorpos=" + curPos;
  20. return this.postText(url, fullText, callback);
  21. };
  22. proxy.postBodyText = function (uriTemplate, httpMethod, format, curPos, fullText, callback) {
  23. var url = "request/content?uri=" + encodeURIComponent(uriTemplate) + "&method=" + encodeURIComponent(httpMethod) + "&op=autocomplete" + "&cursorpos=" + curPos + "&format0=" + format;
  24. return this.postText(url, fullText, callback);
  25. };
  26. proxy.validateText = function (type, uriTemplate, httpMethod, format, fullText, callbackSuc, callbackErr) {
  27. var url = "";
  28. if(type == 'uri'){
  29. url = "request/uri?uri=" + encodeURIComponent(uriTemplate) + "&method=" + encodeURIComponent(httpMethod) + "&op=validate";
  30. }
  31. else{
  32. url = "request/content?uri=" + encodeURIComponent(uriTemplate) + "&method=" + encodeURIComponent(httpMethod) + "&op=validate&format0="+format;
  33. }
  34. var jqxhr = $.post(url, fullText, function (isValid) {
  35. callbackSuc(isValid);
  36. });
  37. jqxhr.error(function () {
  38. callbackErr();
  39. });
  40. };
  41. proxy.formatRequestBody = function(uriTemplate, httpMethod, rawRequestBody, format, callbackSuc, callbackErr){
  42. var url = "request/content?uri=" + encodeURIComponent(uriTemplate) + "&method=" + encodeURIComponent(httpMethod) + "&op=format" + "&format0=" + format;
  43. $.ajaxSetup({async: false, timeout:10000});
  44. var jqxhr = $.post(url, rawRequestBody, function (formattedText) {
  45. callbackSuc(formattedText);
  46. });
  47. jqxhr.error(function () {
  48. callbackErr();
  49. });
  50. $.ajaxSetup({async: true});
  51. };
  52. proxy.postResContText = function (rawResponse, format, callbackSuc, callbackErr) {
  53. var resContFormaterURL = "response/content?format="+format;
  54. $.ajaxSetup({async: false, timeout:10000});
  55. var jqxhr = $.post(resContFormaterURL, rawResponse, function (formattedText) {
  56. callbackSuc(formattedText);
  57. });
  58. jqxhr.error(function () {
  59. callbackErr();
  60. });
  61. $.ajaxSetup({async: true});
  62. };
  63. proxy.convertRequestBodyFormat = function (uriTemplate, httpMethod, currentFormat, targetFormat, requestBodyText, callbackSuc, callbackErr) {
  64. var url = "request/content?uri=" + encodeURIComponent(uriTemplate) + "&method="+ encodeURIComponent(httpMethod) + "&op=convert&format0=" + currentFormat +"&format1=" + targetFormat;
  65. $.ajaxSetup({async: false, timeout:10000});
  66. var jqxhr = $.post(url, requestBodyText, function (convertResult) {
  67. callbackSuc(convertResult);
  68. });
  69. jqxhr.error(function () {
  70. callbackErr();
  71. });
  72. $.ajaxSetup({async: true});
  73. };
  74. proxy.getResource = function (callbackSuc, callbackErr) {
  75. $.ajaxSetup({cache: false});
  76. var jqxhr = $.getJSON("resources", function (data) {
  77. callbackSuc(data);
  78. });
  79. jqxhr.error(function () {
  80. callbackErr();
  81. });
  82. }