lowercase MiddleWare and fix TypeError in Headers

legacy/0.4
Martin Zimmermann 11 years ago
parent 1e3245098b
commit af6695e935

@ -174,7 +174,7 @@ def make_app(conf=None):
app = ProxyFix(
wsgi.SubURI(
wsgi.CORSMiddleWare(
wsgi.CORSMiddleware(
SharedDataMiddleware(isso, {
'/js': join(dirname(__file__), 'js/'),
'/css': join(dirname(__file__), 'css/')}),

@ -1,5 +1,8 @@
# -*- encoding: utf-8 -*-
from werkzeug.datastructures import Headers
class SubURI(object):
def __init__(self, app):
@ -17,7 +20,7 @@ class SubURI(object):
return self.app(environ, start_response)
class CORSMiddleWare(object):
class CORSMiddleware(object):
def __init__(self, app, hosts):
self.app = app
@ -34,12 +37,13 @@ class CORSMiddleWare(object):
else:
origin = host.rstrip("/")
headers.append(("Access-Control-Allow-Origin", origin))
headers.append(("Access-Control-Allow-Headers", "Origin, Content-Type"))
headers.append(("Access-Control-Allow-Credentials", "true"))
headers.append(("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"))
headers.append(("Access-Control-Expose-Headers", "X-Set-Cookie"))
return start_response(status, headers, exc_info)
headers = Headers(headers)
headers.add("Access-Control-Allow-Origin", origin)
headers.add("Access-Control-Allow-Headers", "Origin, Content-Type")
headers.add("Access-Control-Allow-Credentials", "true")
headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
headers.add("Access-Control-Expose-Headers", "X-Set-Cookie")
return start_response(status, headers.to_list(), exc_info)
if environ.get("REQUEST_METHOD") == "OPTIONS":
add_cors_headers("200 Ok", [("Content-Type", "text/plain")])

@ -1,8 +1,10 @@
from __future__ import unicode_literals
from werkzeug.test import Client
from werkzeug.wrappers import Response
from isso.wsgi import CORSMiddleWare
from isso.wsgi import CORSMiddleware
def hello_world(environ, start_response):
@ -12,7 +14,7 @@ def hello_world(environ, start_response):
def test_simple_CORS():
app = CORSMiddleWare(hello_world, hosts=[
app = CORSMiddleware(hello_world, hosts=[
"https://example.tld/",
"http://example.tld/",
"http://example.tld",
@ -40,7 +42,7 @@ def test_simple_CORS():
def test_preflight_CORS():
app = CORSMiddleWare(hello_world, hosts=["http://example.tld"])
app = CORSMiddleware(hello_world, hosts=["http://example.tld"])
client = Client(app, Response)
rv = client.open(method="OPTIONS", path="/", headers={"ORIGIN": "http://example.tld"})

Loading…
Cancel
Save