MCPcopy Create free account
hub / github.com/StackStorm/st2 / custom_start_response

Method custom_start_response

st2common/st2common/middleware/cors.py:42–96  ·  view source on GitHub ↗
(status, headers, exc_info=None)

Source from the content-addressed store, hash-verified

40 request = Request(environ)
41
42 def custom_start_response(status, headers, exc_info=None):
43 headers = ResponseHeaders(headers)
44
45 origin = request.headers.get("Origin")
46 origins = OrderedSet(cfg.CONF.api.allow_origin)
47
48 # Build a list of the default allowed origins
49 public_api_url = cfg.CONF.auth.api_url
50
51 # Default gulp development server WebUI URL
52 origins.add("http://127.0.0.1:3000")
53
54 # By default WebUI simple http server listens on 8080
55 origins.add("http://localhost:8080")
56 origins.add("http://127.0.0.1:8080")
57
58 if public_api_url:
59 # Public API URL
60 origins.add(public_api_url)
61
62 origins = list(origins)
63
64 if origin:
65 if "*" in origins:
66 origin_allowed = origin
67 else:
68 # See http://www.w3.org/TR/cors/#access-control-allow-origin-response-header
69 origin_allowed = origin if origin in origins else list(origins)[0]
70 else:
71 origin_allowed = list(origins)[0]
72
73 methods_allowed = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
74 request_headers_allowed = [
75 "Content-Type",
76 "Authorization",
77 HEADER_ATTRIBUTE_NAME,
78 HEADER_API_KEY_ATTRIBUTE_NAME,
79 REQUEST_ID_HEADER,
80 ]
81 response_headers_allowed = [
82 "Content-Type",
83 "X-Limit",
84 "X-Total-Count",
85 REQUEST_ID_HEADER,
86 ]
87
88 headers["Access-Control-Allow-Origin"] = origin_allowed
89 headers["Access-Control-Allow-Methods"] = ",".join(methods_allowed)
90 headers["Access-Control-Allow-Headers"] = ",".join(request_headers_allowed)
91 headers["Access-Control-Allow-Credentials"] = "true"
92 headers["Access-Control-Expose-Headers"] = ",".join(
93 response_headers_allowed
94 )
95
96 return start_response(status, headers._items, exc_info)
97
98 if request.method == "OPTIONS":
99 return Response()(environ, custom_start_response)

Callers

nothing calls this directly

Calls 3

addMethod · 0.95
OrderedSetClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected