CORS

11 views
Skip to first unread message

Roman Mishin

unread,
Jul 7, 2011, 7:09:58 AM7/7/11
to bandicoot
Hi,

Please, explain how do you run demo Webapps from examples.

file:///.../examples/unique.html
and
http://localhost:12345/Unique
are of the different origin.

Firefox 5 and Chrome 12 do not allow XMLHttpRequest:
Exception... "Component returned failure code: 0x80004005
(NS_ERROR_FAILURE)"
NETWORK_ERR: XMLHttpRequest Exception 101

In case of HTTP server:
http://localhost/unique.html
and
http://localhost:12345/Unique
are also of different origin due to the different port.

So the examples as they are just do not work for me.

And I do not understand this subject yet:
How is CORS support related to Bandicoot?
I mean, the only thing I see is how browser enforces the policy.

--
Roman

Ostap Cherkashin

unread,
Jul 8, 2011, 8:57:27 AM7/8/11
to band...@googlegroups.com
Hello

Here are the steps to run the examples:

1. startup an example program (e.g. from the unpacked bandicoot binary distribution):

$ mkdir data
$ ./bandicoot start -d data -s data/state -c examples/unique.b -p 12345

2. open the following url in your browser

file:///path/to/examples/unique.html

3. click Run in the browser

This procedure works well for me on Linux in Firefox 5 and Chrome 14-dev (but I also ran it quite some time ago with older versions of Chrome).

If these steps don't work for you try opening the JavaScript console in Chrome or Firebug in Firefox and check the network requests. You should see something like this:

1. GET file:///path/to/examples/unique.html
2. OPTIONS http://localhost:12345/Unique
3. POST http://localhost:12345/Unique

You can also try to telnet to localhost 12345 or test it using curl, to see if you can reach the bandicoot at all.

With regard to the relationship between CORS (http://www.w3.org/TR/cors/) and Bandicoot, the specification contains the following words in the abstract:

"... If such an API <EDIT>e.g. cross-origin enabled XMLHttpRequest</EDIT> is used on http://example.org resources, a resource on http://hello-world.example can opt in using the mechanism described by this specification (e.g., specifying Access-Control-Allow-Origin: http://example.org as response header), which would allow that resource to be fetched cross-origin from http://example.org."

Bandicoot handles the Access-Control-Allow-* headers so that it could be used with resources from other locations. In particular the mechanism described in "6.1.5. Cross-Origin Request with Preflight" is employed in the situation above (http://localhost:12345/Unique).

In JavaScript console I can see that the preflight request on step 2 contains the following headers:
---
Access-Control-Request-Headers:Origin, Content-Type
Access-Control-Request-Method:POST
---

... and then Bandicoot replies with:
---
Access-Control-Allow-Headers: Content-Type, Content-Length
Access-Control-Allow-Methods: OPTIONS, GET, POST
Access-Control-Allow-Origin: *
---

... thus making it possible for a user agent to proceed to step 3.

Regards
- Ostap

Roman Mishin

unread,
Jul 8, 2011, 10:00:05 AM7/8/11
to bandicoot
Thank you, Ostap.

I misunderstood the program structure. Sorry.
Should be restarting Bandicoot with -c examples/unique.b

The examples work as intended.

Thanks for your time.

-
Roman

Julius Chrobak

unread,
Jul 13, 2011, 2:30:41 AM7/13/11
to band...@googlegroups.com
hi,

this is a proposal patch to implement primitive parameters for bandicoot functions. This change allows to execute HTTP GET/POST with parameters in the URL and use them for select and extend operators. The grammar change allows to specify multiple primitive parameters as well as one relational parameter for a function.

Feel free to comment on this change and propose any improvements.

Julius


Example 1:

bandicoot function :
---------------
rel Data {
x: int
}

d: Data;

fn Test(i: int): Data
{
return d select(x == i);
}
---------------

curl request example:
---------------
[~] curl http://localhost:12345/Test?i=1
x:int
[~]
---------------


Example 2:

bandicoot function:
---------------
rel Data {
x: int
}

fn Test(d: Data, i: int): Data
{
return d select(x == i);
}
---------------

curl request example:
---------------
[~] echo -e "x:int\n1\n2" | curl --data-binary @- http://localhost:12345/Test?i=1
x:int
1
[~]
---------------

0001-primitive-parameters-to-functions.patch

julo

unread,
Jul 13, 2011, 2:33:21 AM7/13/11
to bandicoot
Pls ignore this message. I've attached it to the CORS discussion
thread by mistate.


On Jul 13, 8:30 am, Julius Chrobak <j...@bandilab.org> wrote:
> hi,
>
> this is a proposal patch to implement primitive parameters for bandicoot functions. This change allows to execute HTTP GET/POST with parameters in the URL and use them for select and extend operators. The grammar change allows to specify multiple primitive parameters as well as one relational parameter for a function.
>
> Feel free to comment on this change and propose any improvements.
>
> Julius
>
> Example 1:
>
> bandicoot function :
> ---------------
> rel Data {
>         x: int
>
> }
>
> d: Data;
>
> fn Test(i: int): Data
> {
>         return d select(x == i);}
>
> ---------------
>
> curl request example:
> ---------------
> [~] curlhttp://localhost:12345/Test?i=1
> x:int
> [~]
> ---------------
>
> Example 2:
>
> bandicoot function:
> ---------------
> rel Data {
>         x: int
>
> }
>
> fn Test(d: Data, i: int): Data
> {
>         return d select(x == i);}
>
> ---------------
>
> curl request example:
> ---------------
> [~] echo -e "x:int\n1\n2" | curl --data-binary @-http://localhost:12345/Test?i=1
> x:int
> 1
> [~]
> ---------------
>
>  0001-primitive-parameters-to-functions.patch
> 73KViewDownload

Julius Chrobak

unread,
Jul 13, 2011, 2:34:50 AM7/13/11
to band...@googlegroups.com
hi,

this is a proposal patch to implement primitive parameters for bandicoot functions. This change allows to execute HTTP GET/POST with parameters in the URL and use them for select and extend operators. The grammar change allows to specify multiple primitive parameters as well as one relational parameter for a function.

Feel free to comment on this change and propose any improvements.

Julius


Example 1:

bandicoot function :
---------------
rel Data {
x: int
}

d: Data;

fn Test(i: int): Data
{
return d select(x == i);
}
---------------

curl request example:
---------------

x:int
[~] 
---------------


Example 2:

bandicoot function:
---------------
rel Data {
x: int
}

fn Test(d: Data, i: int): Data
{
return d select(x == i);
}
---------------

curl request example:
---------------
[~] echo -e "x:int\n1\n2" | curl --data-binary @- http://localhost:12345/Test?i=1
0001-primitive-parameters-to-functions.patch

julo

unread,
Jul 13, 2011, 2:35:30 AM7/13/11
to bandicoot
Reply all
Reply to author
Forward
0 new messages