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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE> [99s-extend] Cowboy CORS
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Cowboy%20CORS&In-Reply-To=%3CCD96D43A.4E43%25christopher.phillips%40turner.com%3E">
<META NAME="robots" CONTENT="index,nofollow">
<style type="text/css">
pre {
white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */
}
</style>
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="000112.html">
<LINK REL="Next" HREF="000114.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[99s-extend] Cowboy CORS</H1>
<B>Phillips, Christopher</B>
<A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Cowboy%20CORS&In-Reply-To=%3CCD96D43A.4E43%25christopher.phillips%40turner.com%3E"
TITLE="[99s-extend] Cowboy CORS">Christopher.Phillips at turner.com
</A><BR>
<I>Fri Apr 19 17:08:03 CEST 2013</I>
<P><UL>
<LI>Previous message: <A HREF="000112.html">[99s-extend] Cowboy CORS
</A></li>
<LI>Next message: <A HREF="000114.html">[99s-extend] 505 error
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#113">[ date ]</a>
<a href="thread.html#113">[ thread ]</a>
<a href="subject.html#113">[ subject ]</a>
<a href="author.html#113">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE> When querying to the VM from a browser, is Chrome complaining that it's a cross domain request in the console? Or something else?
Is the OPTIONS request firing and failing, or is it the POST that is failing (in the network tab)?
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 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.
From: Lee Sylvester <<A HREF="https://lists.ninenines.eu/listinfo/extend">lee.sylvester at gmail.com</A><mailto:<A HREF="https://lists.ninenines.eu/listinfo/extend">lee.sylvester at gmail.com</A>>>
Date: Friday, April 19, 2013 10:47 AM
To: "<A HREF="https://lists.ninenines.eu/listinfo/extend">extend at lists.ninenines.eu</A><mailto:<A HREF="https://lists.ninenines.eu/listinfo/extend">extend at lists.ninenines.eu</A>>" <<A HREF="https://lists.ninenines.eu/listinfo/extend">extend at lists.ninenines.eu</A><mailto:<A HREF="https://lists.ninenines.eu/listinfo/extend">extend at lists.ninenines.eu</A>>>
Subject: [99s-extend] Cowboy CORS
Hi guys,
So, I thought I had this resolved, as I managed to get it working locally, but across different local domains (test.localhost.com<<A HREF="http://test.localhost.com">http://test.localhost.com</A>> and cowboy.localhost.com<<A HREF="http://cowboy.localhost.com">http://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:
1.
Request URL:
<A HREF="http://www.example.com/">http://www.example.com/</A>
2.
Request Method:
OPTIONS
3.
Status Code:
200 OK
4. Request Headersview source
*
Accept:
*/*
*
Accept-Charset:
ISO-8859-1,utf-8;q=0.7,*;q=0.3
*
Accept-Encoding:
gzip,deflate,sdch
*
Accept-Language:
en-US,en;q=0.8
*
Access-Control-Request-Headers:
origin, method, content-type
*
Access-Control-Request-Method:
POST
*
Connection:
keep-alive
*
Host:
www.example.com<<A HREF="http://www.example.com">http://www.example.com</A>>
*
Origin:
<A HREF="http://test.localhost.com:8889">http://test.localhost.com:8889</A>
*
Referer:
<A HREF="http://test.localhost.com:8889/">http://test.localhost.com:8889/</A>
*
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
5. Response Headersview source
*
Access-Control-Allow-Headers:
Content-Type, X-Requested-With, Origin, Method
*
Access-Control-Allow-Methods:
GET, POST, OPTIONS
*
Access-Control-Allow-Origin:
*
*
connection:
keep-alive
*
content-length:
0
*
date:
Fri, 19 Apr 2013 14:40:00 GMT
*
server:
Cowboy
And then this is the POST response:
1.
Request URL:
<A HREF="http://www.example.com/">http://www.example.com/</A>
2. Request Headersview parsed
* POST <A HREF="http://www.example.com/">http://www.example.com/</A> HTTP/1.1 Origin: <A HREF="http://test.localhost.com:8889">http://test.localhost.com:8889</A> Referer: <A HREF="http://test.localhost.com:8889/">http://test.localhost.com:8889/</A> method: POST <A HREF="http://www.example.com/">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
3. Form Dataview parsed
* data={"Type":"auth_request","Authentication":"public","Authorization":null,"Domain":"www.example.com<<A HREF="http://www.example.com">http://www.example.com</A>>","Application":"test_app","Ident":"lee"}
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?
The cowboy_req:set_resp_header is happening in the handle… So
handle(Req, State) ->
Reply = case cowboy_req:method(Req) of
{<<"POST">>, Req2} ->
Req3 = cowboy_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req2),
[snip]
Thanks,
Lee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <<A HREF="http://lists.ninenines.eu/archives/extend/attachments/20130419/383515dd/attachment.html">http://lists.ninenines.eu/archives/extend/attachments/20130419/383515dd/attachment.html</A>>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000112.html">[99s-extend] Cowboy CORS
</A></li>
<LI>Next message: <A HREF="000114.html">[99s-extend] 505 error
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#113">[ date ]</a>
<a href="thread.html#113">[ thread ]</a>
<a href="subject.html#113">[ subject ]</a>
<a href="author.html#113">[ author ]</a>
</LI>
</UL>
<hr>
<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
mailing list</a><br>
</body></html>
|