1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
<tt>
<html><br>
<head><br>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"><br>
</head><br>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif; "><br>
<div> When querying to the VM from a browser, is Chrome complaining that it's a cross domain request in the console? Or something else? </div><br>
<div><br><br>
</div><br>
<div> Is the OPTIONS request firing and failing, or is it the POST that is failing (in the network tab)? </div><br>
<div><br><br>
</div><br>
<div> If it's working in a cross origin context for you locally across different domains (I.e., the browser is sending the CORS headers on the request, and you're seeing the right headers on the response, and the browser is handling them properly, such that<br>
you can retrieve the response from your Javascript), then it seems unlikely to be a CORS issue, but maybe a config or proxy or code issue in your handler. </div><br>
<div><br><br>
</div><br>
<div><br><br>
</div><br>
<span id="OLK_SRC_BODY_SECTION"><br>
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><br>
<span style="font-weight:bold">From: </span>Lee Sylvester <<a href="mailto:[email protected]">[email protected]</a>><br><br>
<span style="font-weight:bold">Date: </span>Friday, April 19, 2013 10:47 AM<br><br>
<span style="font-weight:bold">To: </span>"<a href="mailto:[email protected]">[email protected]</a>" <<a href="mailto:[email protected]">[email protected]</a>><br><br>
<span style="font-weight:bold">Subject: </span>[99s-extend] Cowboy CORS<br><br>
</div><br>
<div><br><br>
</div><br>
<div><br>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br>
<div>Hi guys,</div><br>
<div><br><br>
</div><br>
<div>So, I thought I had this resolved, as I managed to get it working locally, but across different local domains (<a href="http://test.localhost.com">test.localhost.com</a> and<br>
<a href="http://cowboy.localhost.com">cowboy.localhost.com</a>). However, now I've deployed my app to a VM, I simply can't get CORS working in Cowboy. Here's the OPTIONS response from Chrome's console:</div><br>
<div><br><br>
</div><br>
<div><br><br>
</div><br>
<div><br>
<ol class="outline-disclosure" tabindex="0" style="box-sizing: border-box; font-size: 11px; list-style-type: none; -webkit-padding-start: 12px; margin: 0px; outline: none; font-family: 'Lucida Grande', sans-serif; background-color: rgb(255, 255, 255); "><br>
<li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Request URL:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
<a href="http://www.example.com/">http://www.example.com/</a></div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Request Method:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
OPTIONS</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Status Code:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
200 OK</div><br>
</li><li title="" class="parent expanded" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -12px; word-wrap: break-word; -webkit-user-select: none; font-weight: bold;"><br>
Request Headers<span class="header-toggle" style="box-sizing: border-box; display: inline; margin-left: 30px; font-weight: normal; color: rgb(115, 115, 115);">view source</span><br>
<ol class="children expanded" style="box-sizing: border-box; position: relative; margin: 0px; cursor: default; min-width: 100%; padding: 2px 6px !important; list-style-type: none; -webkit-padding-start: 12px; "><br>
<li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Accept:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
*/*</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Accept-Charset:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
ISO-8859-1,utf-8;q=0.7,*;q=0.3</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Accept-Encoding:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
gzip,deflate,sdch</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Accept-Language:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
en-US,en;q=0.8</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Access-Control-Request-Headers:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
origin, method, content-type</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Access-Control-Request-Method:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
POST</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Connection:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
keep-alive</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Host:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
<a href="http://www.example.com">www.example.com</a></div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Origin:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
<a href="http://test.localhost.com:8889">http://test.localhost.com:8889</a></div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Referer:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
<a href="http://test.localhost.com:8889/">http://test.localhost.com:8889/</a></div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
User-Agent:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31</div><br>
</li></ol><br>
</li><li title="" class="parent expanded" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -12px; word-wrap: break-word; -webkit-user-select: none; font-weight: bold;"><br>
Response Headers<span class="header-toggle" style="box-sizing: border-box; display: inline; margin-left: 30px; font-weight: normal; color: rgb(115, 115, 115);">view source</span><br>
<ol class="children expanded" style="box-sizing: border-box; position: relative; margin: 0px; cursor: default; min-width: 100%; padding: 2px 6px !important; list-style-type: none; -webkit-padding-start: 12px; "><br>
<li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Access-Control-Allow-Headers:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
Content-Type, X-Requested-With, Origin, Method</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Access-Control-Allow-Methods:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
GET, POST, OPTIONS</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Access-Control-Allow-Origin:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
*</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
connection:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
keep-alive</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
content-length:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
0</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
date:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
Fri, 19 Apr 2013 14:40:00 GMT</div><br>
</li><li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
server:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
Cowboy</div><br>
</li></ol><br>
</li></ol><br>
<div><br><br>
</div><br>
</div><br>
<div>And then this is the POST response:</div><br>
<div><br><br>
</div><br>
<div><br>
<ol class="outline-disclosure" tabindex="0" style="box-sizing: border-box; font-size: 11px; list-style-type: none; -webkit-padding-start: 12px; margin: 0px; outline: none; font-family: 'Lucida Grande', sans-serif; background-color: rgb(255, 255, 255); "><br>
<li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word;"><br>
<div class="header-name" style="box-sizing: border-box; color: rgb(84, 84, 84); display: inline-block; margin-right: 0.5em; font-weight: bold; vertical-align: top; white-space: pre-wrap;"><br>
Request URL:</div><br>
<div class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; "><br>
<a href="http://www.example.com/">http://www.example.com/</a></div><br>
</li><li title="" class="parent expanded" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -12px; word-wrap: break-word; -webkit-user-select: none; font-weight: bold;"><br>
Request Headers<span class="header-toggle" style="box-sizing: border-box; display: inline; margin-left: 30px; font-weight: normal; color: rgb(115, 115, 115);">view parsed</span><br>
<ol class="children expanded" style="box-sizing: border-box; position: relative; margin: 0px; cursor: default; min-width: 100%; padding: 2px 6px !important; list-style-type: none; -webkit-padding-start: 12px; "><br>
<li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<span class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; ">POST<br>
<a href="http://www.example.com/">http://www.example.com/</a> HTTP/1.1 Origin: <a href="http://test.localhost.com:8889"><br>
http://test.localhost.com:8889</a> Referer: <a href="http://test.localhost.com:8889/"><br>
http://test.localhost.com:8889/</a> method: POST <a href="http://www.example.com/"><br>
http://www.example.com/</a> HTTP/1.1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31 content-type: application/x-www-form-urlencoded</span></li></ol><br>
</li><li title="" class="parent expanded" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -12px; word-wrap: break-word; -webkit-user-select: none; font-weight: bold;"><br>
Form Data<span class="header-toggle" style="box-sizing: border-box; display: inline; margin-left: 30px; font-weight: normal; color: rgb(115, 115, 115);">view parsed</span><br>
<ol class="children expanded" style="box-sizing: border-box; position: relative; margin: 0px; cursor: default; min-width: 100%; padding: 2px 6px !important; list-style-type: none; -webkit-padding-start: 12px; "><br>
<li title="" style="box-sizing: border-box; padding: 0px 0px 0px 14px; margin-top: 1px; margin-left: -2px; word-wrap: break-word; white-space: nowrap;"><br>
<span class="header-value source-code" style="box-sizing: border-box; font-family: Menlo, monospace; white-space: pre-wrap; display: inline; margin-right: 100px; word-break: break-all; margin-top: 1px; ">data={"Type":"auth_request","Authentication":"public","Authorization":null,"Domain":"<a href="http://www.example.com">www.example.com</a>","Application":"test_app","Ident":"lee"}</span></li></ol><br>
</li></ol><br>
<div><br><br>
</div><br>
</div><br>
<div>I am setting {<<"Access-Control-Allow-Origin">>, <<"*">>} in the headers param of cowboy_req:reply and the cowboy_req:set_resp_header, but neither seems to be working. Can anyone spot what I might be doing wrong?</div><br>
<div><br><br>
</div><br>
<div>The cowboy_req:set_resp_header is happening in the handle� So</div><br>
<div><br><br>
</div><br>
<div><br>
<div>handle(Req, State) -></div><br>
<div><span class="Apple-tab-span" style="white-space:pre"></span>Reply = case cowboy_req:method(Req) of</div><br>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{<<"POST">>, Req2} -></div><br>
<div><span class="Apple-tab-span" style="white-space:pre"></span>Req3 = cowboy_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req2),</div><br>
</div><br>
<div>[snip]</div><br>
<div><br><br>
</div><br>
<div><br><br>
</div><br>
<div>Thanks,</div><br>
<div>Lee</div><br>
<div><br><br>
</div><br>
</div><br>
</div><br>
</span><br>
</body><br>
</html><br>
</tt>
|