lowercase MiddleWare and fix TypeError in Headers
This commit is contained in:
parent
1e3245098b
commit
af6695e935
@ -174,7 +174,7 @@ def make_app(conf=None):
|
|||||||
|
|
||||||
app = ProxyFix(
|
app = ProxyFix(
|
||||||
wsgi.SubURI(
|
wsgi.SubURI(
|
||||||
wsgi.CORSMiddleWare(
|
wsgi.CORSMiddleware(
|
||||||
SharedDataMiddleware(isso, {
|
SharedDataMiddleware(isso, {
|
||||||
'/js': join(dirname(__file__), 'js/'),
|
'/js': join(dirname(__file__), 'js/'),
|
||||||
'/css': join(dirname(__file__), 'css/')}),
|
'/css': join(dirname(__file__), 'css/')}),
|
||||||
|
18
isso/wsgi.py
18
isso/wsgi.py
@ -1,5 +1,8 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
from werkzeug.datastructures import Headers
|
||||||
|
|
||||||
|
|
||||||
class SubURI(object):
|
class SubURI(object):
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
@ -17,7 +20,7 @@ class SubURI(object):
|
|||||||
return self.app(environ, start_response)
|
return self.app(environ, start_response)
|
||||||
|
|
||||||
|
|
||||||
class CORSMiddleWare(object):
|
class CORSMiddleware(object):
|
||||||
|
|
||||||
def __init__(self, app, hosts):
|
def __init__(self, app, hosts):
|
||||||
self.app = app
|
self.app = app
|
||||||
@ -34,12 +37,13 @@ class CORSMiddleWare(object):
|
|||||||
else:
|
else:
|
||||||
origin = host.rstrip("/")
|
origin = host.rstrip("/")
|
||||||
|
|
||||||
headers.append(("Access-Control-Allow-Origin", origin))
|
headers = Headers(headers)
|
||||||
headers.append(("Access-Control-Allow-Headers", "Origin, Content-Type"))
|
headers.add("Access-Control-Allow-Origin", origin)
|
||||||
headers.append(("Access-Control-Allow-Credentials", "true"))
|
headers.add("Access-Control-Allow-Headers", "Origin, Content-Type")
|
||||||
headers.append(("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"))
|
headers.add("Access-Control-Allow-Credentials", "true")
|
||||||
headers.append(("Access-Control-Expose-Headers", "X-Set-Cookie"))
|
headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
|
||||||
return start_response(status, headers, exc_info)
|
headers.add("Access-Control-Expose-Headers", "X-Set-Cookie")
|
||||||
|
return start_response(status, headers.to_list(), exc_info)
|
||||||
|
|
||||||
if environ.get("REQUEST_METHOD") == "OPTIONS":
|
if environ.get("REQUEST_METHOD") == "OPTIONS":
|
||||||
add_cors_headers("200 Ok", [("Content-Type", "text/plain")])
|
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.test import Client
|
||||||
from werkzeug.wrappers import Response
|
from werkzeug.wrappers import Response
|
||||||
|
|
||||||
from isso.wsgi import CORSMiddleWare
|
from isso.wsgi import CORSMiddleware
|
||||||
|
|
||||||
|
|
||||||
def hello_world(environ, start_response):
|
def hello_world(environ, start_response):
|
||||||
@ -12,7 +14,7 @@ def hello_world(environ, start_response):
|
|||||||
|
|
||||||
def test_simple_CORS():
|
def test_simple_CORS():
|
||||||
|
|
||||||
app = CORSMiddleWare(hello_world, hosts=[
|
app = CORSMiddleware(hello_world, hosts=[
|
||||||
"https://example.tld/",
|
"https://example.tld/",
|
||||||
"http://example.tld/",
|
"http://example.tld/",
|
||||||
"http://example.tld",
|
"http://example.tld",
|
||||||
@ -40,7 +42,7 @@ def test_simple_CORS():
|
|||||||
|
|
||||||
def test_preflight_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)
|
client = Client(app, Response)
|
||||||
|
|
||||||
rv = client.open(method="OPTIONS", path="/", headers={"ORIGIN": "http://example.tld"})
|
rv = client.open(method="OPTIONS", path="/", headers={"ORIGIN": "http://example.tld"})
|
||||||
|
Loading…
Reference in New Issue
Block a user