Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3fa450b

Browse filesBrowse files
committed
Moved samples to http/
1 parent d04c9c0 commit 3fa450b
Copy full SHA for 3fa450b

File tree

Expand file treeCollapse file tree

4 files changed

+53
-76
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+53
-76
lines changed

‎functions/cors/README.md

Copy file name to clipboardExpand all lines: functions/cors/README.md
-11Lines changed: 0 additions & 11 deletions
This file was deleted.

‎functions/cors/main.py

Copy file name to clipboardExpand all lines: functions/cors/main.py
-65Lines changed: 0 additions & 65 deletions
This file was deleted.

‎functions/http/main.py

Copy file name to clipboardExpand all lines: functions/http/main.py
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,56 @@ def get_signed_url(request):
118118

119119
return url
120120
# [END functions_http_signed_url]
121+
122+
123+
# [START functions_http_cors]
124+
def cors_enabled_function(request):
125+
# Set CORS headers for the preflight request
126+
# e.g. allows GETs from any origin with the Content-Type header
127+
# and cache preflight response for an 3600s
128+
129+
# Send response to OPTIONS requests and terminate the function execution
130+
if request.method == 'OPTIONS':
131+
headers = {
132+
'Access-Control-Allow-Origin': '*',
133+
'Access-Control-Allow-Methods': 'GET',
134+
'Access-Control-Allow-Headers': 'Content-Type',
135+
'Access-Control-Max-Age': '3600'
136+
}
137+
138+
return ('', 204, headers)
139+
140+
# Set CORS headers for the main request
141+
headers = {
142+
'Access-Control-Allow-Origin': '*'
143+
}
144+
145+
return ('Hello World!', 200, headers)
146+
# [END functions_http_cors]
147+
148+
149+
# [START functions_http_cors_auth]
150+
def cors_enabled_function_auth(request):
151+
# Set CORS headers for preflight requests
152+
# e.g. allows GETS from origin https://mydomain.com with Authorization
153+
# header
154+
155+
# Send response to OPTIONS requests and terminate the function execution
156+
if request.method == 'OPTIONS':
157+
headers = {
158+
'Access-Control-Allow-Origin': 'https://mydomain.com',
159+
'Access-Control-Allow-Methods': 'GET',
160+
'Access-Control-Allow-Headers': 'Authorization',
161+
'Access-Control-Max-Age': '3600',
162+
'Access-Control-Allow-Credentials': 'true'
163+
}
164+
return ('', 204, headers)
165+
166+
# Set CORS headers for main requests
167+
headers = {
168+
'Access-Control-Allow-Origin': 'https://mydomain.com',
169+
'Access-Control-Allow-Credentials': 'true'
170+
}
171+
172+
return ('Hello World!', 200, headers)
173+
# [END functions_http_cors_auth]
File renamed without changes.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.