利用cookie 测试浏览器的缓存机制
来源:互联网 发布:asp网络程序员招聘 编辑:程序博客网 时间:2024/06/06 10:41
利用是否去请求时,至少response header是会存在请求不请求的区别
这样的话,如果去请求的时候,就带上返回新的cookie
然后和老的cookie比较
如果是跟新了,说明,没有去读cache,而是发送请求了
例子测试页面:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script src="http://10.1.146.174/case/js/jquery.js" type="text/javascript"></script><script src="http://10.1.146.174/case/js/browsertool.js" type="text/javascript"></script><script src="http://10.1.146.174/case/js/assert.js" type="text/javascript"></script><script src="http://10.1.146.174/case/JS/BlueFairyCTS.js" type="text/javascript"></script><script src="http://10.1.146.174/case/JS/BlueFairyCTS_Report.js" type="text/javascript"></script</head><body><a>response is max-age=10, so when request this url in the new window in 10 seconds, browser should not send request to server, but local cache</a><iframe id="testpage" src="http://10.1.146.174/service/cachecontrol.py?method=maxage" height="100%" width="100%"></iframe><script type="text/javascript">$("#testpage").load(function(){var ckie = getcookie('time');if(ckie==''){setCookie('time', '2', false, false, false, false); //differce between 2 times,setTimeout("window.open('http://10.1.146.174/case/front/cache/testcache011-maxage-newwindow.html', '_blank');",2000);var rs = new CloseBrowser("","",5,null);rs.Call();//setTimeout("document.execCommand('Refresh');",2000);}else if(ckie=='2'){var content = parent.frames['testpage'].document.body.innerText;assertEquals('maxage1 ',content,'expect the content is maxage1,if request,the server will return maxage2');var ckie1 = getcookie('maxage')assertNotEquals('2',ckie1,'if not request server , the cookie should still be 1');var casename = "testcachemaxage011";var casetype = "CACHE";var description = "test browser open a new window to request this url when server return cache-control: no-cache, and browser will request the server and load new resource";delcookie('time');var debugInfo = ListToStr(ASSERTLIST);var add = new AddTestResult("",casetype,casename,RESULT,description,debugInfo,null);add.Call();var rs = new CloseBrowser("","",5,null);rs.Call();}});</script></body></html>
def maxage():try:if(os.environ.has_key('HTTP_COOKIE')):if(os.environ['HTTP_COOKIE'].find('request=first') >= 0):logger.info('maxage: has cookie maxage=1')ckie = Cookie.SimpleCookie()ckie['request']='first'ckie['maxage']='2'ckie['maxage']['path']='/case'print('Status: 200 OK')print('Content-Type: text/html')print('Cache-Control: max-age=10')print(ckie)print('')print('maxage2')returnlogger.info('maxage: has no cookie')ckie = Cookie.SimpleCookie()ckie['request']='first'ckie['maxage']='1'ckie['maxage']['path']='/case'print('Status: 200 OK')print('Content-Type: text/html')print('Cache-Control: max-age=10')print(ckie)print('')print('maxage1')returnexcept:logger.error(sys.exc_info())return httplib.error()
- 利用cookie 测试浏览器的缓存机制
- 浏览器缓存机制(三)——cookie
- 浏览器的缓存机制
- 浏览器的缓存机制
- 浏览器的缓存机制
- 浏览器的缓存机制
- 浏览器的缓存机制
- 【总结】浏览器的缓存机制
- 浏览器的缓存机制详解
- 浏览器的“刷新”&“缓存机制”
- 浏览器的“刷新”&“缓存机制”
- 浏览器HTTP的缓存机制
- 浏览器的缓存机制详解
- 浏览器http的缓存机制
- 浏览器http的缓存机制
- 浅谈浏览器的缓存机制
- 【缓存】-浏览器缓存机制
- servlet--Cookie浏览器缓存
- 多线程处理与效率问题
- 重装系统后如何恢复mysql数据
- Android 中的WiFi学习笔记(转载)----WIFI启动 代码流程走读---网络连接流程
- java泛型
- 知识点(3)--exe文件中的资源的使用
- 利用cookie 测试浏览器的缓存机制
- Portal官网上的介绍3技术规格
- 腾讯WSD:手机QQ浏览器界面布局设计心得
- 重载下标运算符
- XP系统中设置文件夹的权限
- 反射
- 实体框架
- 项目经理、系统架构师或技术骨干应该具备的水平
- poj 1456 supermarket