可轻松的修改 XHR 的请求和响应:XHook

jopen 11年前

XHook 可轻松的修改 XHR 的请求和响应。主要用于:

  • Cache requests in memory, localStorage, etc.

  • Insert authentication headers

  • Simulate responses

    • Create fake transparent backends for testing purposes

  • Sending Error statistics to Google Analytics

  • Polyfil CORS, by offloading requests to an iframe then splicing the response back in, see XDomain

  • Devious practical jokes

  • Preflight GZip compression, see XZip (In progress)

示例代码:

//modify 'responseText' of 'example2.txt'  xhook.after(function(request, response) {    if(request.url.match(/example\.txt$/))       response.text = response.text.replace(/[aeiou]/g,'z');  });

支持的浏览器:IE8+, Chrome, Firefox, Safari

13074025_u85j.jpg

项目主页:http://www.open-open.com/lib/view/home/1405326930290