Skip to content

Commit eb71990

Browse files
ngin_vhost: support for CORS credentials header
1 parent d7b529d commit eb71990

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ansible/roles/nginx_vhost/defaults/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ nginx_disable_download_disk_buffering: False
113113
# nginx_cors_origin_regexp: '^https?:\/\/(localhost|l-a\.site|.*\.l-a\.site)'
114114
nginx_cors_headers: "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"
115115
nginx_cors_methods: "GET, POST, OPTIONS"
116+
# by default, Access-Control-Allow-Credentials header is not included; to include it, set this to True
117+
nginx_cors_allow_credentials: False

ansible/roles/nginx_vhost/templates/ala_cors.j2

+9
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,26 @@ if ($cors = COPTIONS) {
4141
add_header 'Access-Control-Max-Age' 1728000;
4242
add_header 'Content-Type' 'text/plain; charset=utf-8';
4343
add_header 'Content-Length' 0;
44+
{% if nginx_cors_allow_credentials == True %}
45+
add_header 'Access-Control-Allow-Credentials' 'true';
46+
{% endif %}
4447
return 204;
4548
}
4649
if ($cors = CPOST) {
4750
add_header 'Access-Control-Allow-Origin' '*';
4851
add_header 'Access-Control-Allow-Methods' '{{ nginx_cors_methods }}';
4952
add_header 'Access-Control-Allow-Headers' '{{ nginx_cors_headers }}';
5053
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
54+
{% if nginx_cors_allow_credentials == True %}
55+
add_header 'Access-Control-Allow-Credentials' 'true';
56+
{% endif %}
5157
}
5258
if ($cors = CGET) {
5359
add_header 'Access-Control-Allow-Origin' '*' always;
5460
add_header 'Access-Control-Allow-Methods' '{{ nginx_cors_methods }}';
5561
add_header 'Access-Control-Allow-Headers' '{{ nginx_cors_headers }}';
5662
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
63+
{% if nginx_cors_allow_credentials == True %}
64+
add_header 'Access-Control-Allow-Credentials' 'true';
65+
{% endif %}
5766
}

0 commit comments

Comments
 (0)