添加和替换响应头
wsgiheaders的Python项目详细描述
添加和替换响应头
>;>;@replaceHeader([(r'.*\.html',[('content-type','text/html')]))
…def app(环境,启动响应):
…开始回应('200好',
…[('content-type','text/plain')])
…return[“你好,世界!”]
>>gt;导入WebTest
>>>app=webtest.testapp(应用程序)
>>>res=app.get('/a.txt')
>>>资源内容类型
“文本/纯文本”
>>>res=app.get('/a.html')
>>>资源内容类型
“文本/html”
>>>定义XRD(环境):
…返回[('x-xrds',environ['wsgi.url\u scheme']+'://'”+
环境['服务器名称']+'/svc.xrds')]
…
>>>定义谓词(环境):
…return environ.get('http_accept','').find('application/xrds+xml')!=-
1
…
>>gt;@addheader([(predicate,xrds)])
…def app(环境,启动响应):
…开始回应('200好',
…[('content-type','text/plain')])
…return[“你好,世界!”]
>>>app=webtest.testapp(应用程序)
>>>res=应用程序获取('/')
>;>;>;'x-xrds'在资源标题中
错误
>;>;res=app.get('/',headers={'accept':'application/xrds+xml'})
>>gt;资源标题['x-xrds']
'http://localhost/svc.xrds'
>;>;@replaceHeader([(r'.*\.html',[('content-type','text/html')]))
…def app(环境,启动响应):
…开始回应('200好',
…[('content-type','text/plain')])
…return[“你好,世界!”]
>>gt;导入WebTest
>>>app=webtest.testapp(应用程序)
>>>res=app.get('/a.txt')
>>>资源内容类型
“文本/纯文本”
>>>res=app.get('/a.html')
>>>资源内容类型
“文本/html”
>>>定义XRD(环境):
…返回[('x-xrds',environ['wsgi.url\u scheme']+'://'”+
环境['服务器名称']+'/svc.xrds')]
…
>>>定义谓词(环境):
…return environ.get('http_accept','').find('application/xrds+xml')!=-
1
…
>>gt;@addheader([(predicate,xrds)])
…def app(环境,启动响应):
…开始回应('200好',
…[('content-type','text/plain')])
…return[“你好,世界!”]
>>>app=webtest.testapp(应用程序)
>>>res=应用程序获取('/')
>;>;>;'x-xrds'在资源标题中
错误
>;>;res=app.get('/',headers={'accept':'application/xrds+xml'})
>>gt;资源标题['x-xrds']
'http://localhost/svc.xrds'