1| const xhr = new XMLHttpRequest();
2| const url = 'https://bar.other/resources/public-data/';
3|
4| xhr.open('GET', url);
5| xhr.onreadystatechange = someHandler;
6| xhr.send();
GET /resources/public-data/ HTTP/1.1
Host: bar.other
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Connection: keep-alive
Origin: https://foo.example
HTTP/1.1 200 OK
Date: Mon, 01 Dec 2008 00:23:53 GMT
Server: Apache/2
Access-Control-Allow-Origin: *
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/xml
[…XML Data…]
Access-Control-Allow-Origin: https://foo.example
1| const xhr = new XMLHttpRequest();
2| xhr.open('POST', 'https://bar.other/resources/post-here/');
3| xhr.setRequestHeader('X-PINGOTHER', 'pingpong');
4| xhr.setRequestHeader('Content-Type', 'application/xml');
5| xhr.onreadystatechange = handler;
6| xhr.send('<person><name>Arun</name></person>');
Note: As described below, the actual POST request does not include the Access-Control-Request-* headers; they are needed only for the OPTIONS request.
1| OPTIONS /doc HTTP/1.1
2| Host: bar.other
3| User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:71.0) Gecko/20100101 Firefox/71.0
4| Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
5| Accept-Language: en-us,en;q=0.5
6| Accept-Encoding: gzip,deflate
7| Connection: keep-alive
8| Origin: http://foo.example
9| Access-Control-Request-Method: POST
10| Access-Control-Request-Headers: X-PINGOTHER, Content-Type
11|
12|
13| HTTP/1.1 204 No Content
14| Date: Mon, 01 Dec 2008 01:15:39 GMT
15| Server: Apache/2
16| Access-Control-Allow-Origin: https://foo.example
17| Access-Control-Allow-Methods: POST, GET, OPTIONS
18| Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
19| Access-Control-Max-Age: 86400
20| Vary: Accept-Encoding, Origin
21| Keep-Alive: timeout=2, max=100
22| Connection: Keep-Alive
1| OPTIONS /doc HTTP/1.1
2| Host: bar.other
3| User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:71.0) Gecko/20100101 Firefox/71.0
4| Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
5| Accept-Language: en-us,en;q=0.5
6| Accept-Encoding: gzip,deflate
7| Connection: keep-alive
8| X-PINGOTHER: pingpong
9| Content-Type: text/xml; charset=UTF-8
10| Referer: https://foo.example/examples/preflightInvocation.html
11| Content-Length: 55
12| Origin: https://foo.example
13| Pragma: no-cache
14| Cache-Control: no-cache
15|
16| <person><name>Arun</name></person>
17|
18|
19| HTTP/1.1 200 OK
20| Date: Mon, 01 Dec 2008 01:15:40 GMT
21| Server: Apache/2
22| Access-Control-Allow-Origin: https://foo.example
23| Vary: Accept-Encoding, Origin
24| Content-Encoding: gzip
25| Content-Length: 235
26| Keep-Alive: timeout=2, max=99
27| Connection: Keep-Alive
28| Content-Type: text/plain
29|
30| [Some XML payload]
Access-Control-Request-Method: POST
Access-Control-Request-Headers: X-PINGOTHER, Content-Type
Access-Control-Allow-Origin: http://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
Access-Control-Max-Age: 86400
1| const invocation = new XMLHttpRequest();
2| const url = 'http://bar.other/resources/credentialed-content/';
3|
4| function callOtherDomain() {
5| if (invocation) {
6| invocation.open('GET', url, true);
7| invocation.withCredentials = true;
8| invocation.onreadystatechange = handler;
9| invocation.send();
10| }
11| }
1| GET /resources/credentialed-content/ HTTP/1.1
2| Host: bar.other
3| User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:71.0) Gecko/20100101 Firefox/71.0
4| Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
5| Accept-Language: en-us,en;q=0.5
6| Accept-Encoding: gzip,deflate
7| Connection: keep-alive
8| Referer: http://foo.example/examples/credential.html
9| Origin: http://foo.example
10| Cookie: pageAccess=2
11|
12|
13| HTTP/1.1 200 OK
14| Date: Mon, 01 Dec 2008 01:34:52 GMT
15| Server: Apache/2
16| Access-Control-Allow-Origin: https://foo.example
17| Access-Control-Allow-Credentials: true
18| Cache-Control: no-cache
19| Pragma: no-cache
20| Set-Cookie: pageAccess=3; expires=Wed, 31-Dec-2008 01:34:53 GMT
21| Vary: Accept-Encoding, Origin
22| Content-Encoding: gzip
23| Content-Length: 106
24| Keep-Alive: timeout=2, max=100
25| Connection: Keep-Alive
26| Content-Type: text/plain
27|
28|
29| [text/plain payload]
Access-Control-Allow-Origin: <origin> | *
Access-Control-Allow-Origin: https://mozilla.org
Vary: Origin
Access-Control-Expose-Headers: <header-name>[, <header-name>]*
Access-Control-Expose-Headers: X-My-Custom-Header, X-Another-Custom-Header
Access-Control-Max-Age: <delta-seconds>
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: <method>[, <method>]*
Access-Control-Allow-Headers: <header-name>[, <header-name>]*
Origin: <origin>
Access-Control-Request-Method: <method>
Access-Control-Request-Headers: <field-name>[, <field-name>]*