Merge pull request #154 from yekingyan/opt-cors-all

Add support for use '*' to allow CORS for all domains
This commit is contained in:
Alex Yatskov 2020-04-12 09:15:29 -07:00 committed by GitHub
commit b02f9d6c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -162,11 +162,12 @@ class WebServer:
webCorsOriginList.append(webCorsOrigin) webCorsOriginList.append(webCorsOrigin)
corsOrigin = 'http://localhost' corsOrigin = 'http://localhost'
if len(webCorsOriginList) == 1: allowAllCors = '*' in webCorsOriginList # allow CORS for all domains
if len(webCorsOriginList) == 1 and not allowAllCors:
corsOrigin = webCorsOriginList[0] corsOrigin = webCorsOriginList[0]
elif b'origin' in req.headers: elif b'origin' in req.headers:
originStr = req.headers[b'origin'].decode() originStr = req.headers[b'origin'].decode()
if originStr in webCorsOriginList: if originStr in webCorsOriginList or allowAllCors:
corsOrigin = originStr corsOrigin = originStr
headers = [ headers = [