Commits

Atsushi Odagiri committed cee6cb1

regex compiling if basestring instance is passed.

  • Participants
  • Parent commits 537d8d3

Comments (0)

Files changed (1)

File wsgiheaders/__init__.py

 >>> res = app.get('/')
 >>> res.headers['X-XRDS']
 'http://localhost/services.xrds'
+>>> @addheader([('.*', [('X-XRDS', 'http://localhost/services.xrds')])])
+... def app(environ, start_response):
+...     start_response('200 OK',
+...                    [('Content-type', 'text/plain')])
+...     return ['Hello, world!']
+>>> app = webtest.TestApp(app)
+>>> res = app.get('/')
+>>> res.headers['X-XRDS']
+'http://localhost/services.xrds'
 """
 
+import re
 from webob import Request, Response
 
 def addheader(headerConditions):
+    headerConditions = [(re.compile(p) if isinstance(p, basestring) else p,
+                         headers)
+                        for p,headers in headerConditions ]
     def decorator(app):
         def wrap(environ, start_response):
             req = Request(environ)
     return decorator
 
 def replaceheader(headerConditions):
+    headerConditions = [(re.compile(p) if isinstance(p, basestring) else p,
+                         headers)
+                        for p,headers in headerConditions ]
     def decorator(app):
         def wrap(environ, start_response):
             req = Request(environ)