55from __future__ import print_function
66from __future__ import unicode_literals
77
8+ from . import utils
9+
810
911class CORSMiddleware (object ):
10- ALLOW_ORIGIN = "*"
11- ALLOW_HEADERS = ', ' .join ([
12+ ALLOW_ORIGIN = utils . to_native ( '*' )
13+ ALLOW_HEADERS = utils . to_native ( ', ' .join ([
1214 'Content-Type' ,
1315 'X-AVOSCloud-Application-Id' ,
1416 'X-AVOSCloud-Application-Key' ,
@@ -30,28 +32,28 @@ class CORSMiddleware(object):
3032 'X-LC-Session' ,
3133 'X-LC-Sign' ,
3234 'X-LC-UA' ,
33- ])
34- ALLOW_METHODS = ', ' .join (['PUT' , 'GET' , 'POST' , 'DELETE' , 'OPTIONS' ])
35- MAX_AGE = '86400'
35+ ]))
36+ ALLOW_METHODS = utils . to_native ( ', ' .join (['PUT' , 'GET' , 'POST' , 'DELETE' , 'OPTIONS' ]) )
37+ MAX_AGE = utils . to_native ( '86400' )
3638
3739 def __init__ (self , app ):
3840 self .app = app
3941
4042 def __call__ (self , environ , start_response ):
4143 if environ ['REQUEST_METHOD' ] == 'OPTIONS' :
42- start_response ('200 OK' , [
43- ('Access-Control-Allow-Origin' , environ .get ('HTTP_ORIGIN' , self .ALLOW_ORIGIN )),
44- ('Access-Control-Allow-Headers' , self .ALLOW_HEADERS ),
45- ('Access-Control-Allow-Methods' , self .ALLOW_METHODS ),
46- ('Access-Control-Max-Age' , self .MAX_AGE )
44+ start_response (utils . to_native ( '200 OK' ) , [
45+ (utils . to_native ( 'Access-Control-Allow-Origin' ) , environ .get ('HTTP_ORIGIN' , self .ALLOW_ORIGIN )),
46+ (utils . to_native ( 'Access-Control-Allow-Headers' ) , self .ALLOW_HEADERS ),
47+ (utils . to_native ( 'Access-Control-Allow-Methods' ) , self .ALLOW_METHODS ),
48+ (utils . to_native ( 'Access-Control-Max-Age' ) , self .MAX_AGE )
4749 ])
48- return [b'' ]
50+ return [utils . to_native ( '' ) ]
4951 else :
5052 def cors_start_response (status , headers , exc_info = None ):
51- headers .append (('Access-Control-Allow-Origin' , self .ALLOW_ORIGIN ))
52- headers .append (('Access-Control-Allow-Headers' , self .ALLOW_HEADERS ))
53- headers .append (('Access-Control-Allow-Methods' , self .ALLOW_METHODS ))
54- headers .append (('Access-Control-Max-Age' , self .MAX_AGE ))
53+ headers .append ((utils . to_native ( 'Access-Control-Allow-Origin' ) , self .ALLOW_ORIGIN ))
54+ headers .append ((utils . to_native ( 'Access-Control-Allow-Headers' ) , self .ALLOW_HEADERS ))
55+ headers .append ((utils . to_native ( 'Access-Control-Allow-Methods' ) , self .ALLOW_METHODS ))
56+ headers .append ((utils . to_native ( 'Access-Control-Max-Age' ) , self .MAX_AGE ))
5557 return start_response (status , headers , exc_info )
5658
5759 return self .app (environ , cors_start_response )
0 commit comments