Skip to content

Commit a964025

Browse files
committed
closes #2317
1 parent 75a56da commit a964025

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

Diff for: 5-network/01-fetch/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let promise = fetch(url, [options])
2727
- **`url`** -- the URL to access.
2828
- **`options`** -- optional parameters: method, headers etc.
2929

30-
Without `options`, that is a simple GET request, downloading the contents of the `url`.
30+
Without `options`, this is a simple GET request, downloading the contents of the `url`.
3131

3232
The browser starts the request right away and returns a promise that the calling code should use to get the result.
3333

Diff for: 5-network/05-fetch-crossorigin/article.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -97,39 +97,39 @@ After a while, networking methods appeared in browser JavaScript.
9797
9898
At first, cross-origin requests were forbidden. But as a result of long discussions, cross-origin requests were allowed, but with any new capabilities requiring an explicit allowance by the server, expressed in special headers.
9999
100-
## Simple requests
100+
## Safe requests
101101
102102
There are two types of cross-origin requests:
103103
104-
1. Simple requests.
104+
1. Safe requests.
105105
2. All the others.
106106
107-
Simple Requests are, well, simpler to make, so let's start with them.
107+
Safe Requests are simpler to make, so let's start with them.
108108

109-
A [simple request](http://www.w3.org/TR/cors/#terminology) is a request that satisfies two conditions:
109+
A request is safe if it satisfies two conditions:
110110

111-
1. [Simple method](http://www.w3.org/TR/cors/#simple-method): GET, POST or HEAD
112-
2. [Simple headers](http://www.w3.org/TR/cors/#simple-header) -- the only allowed custom headers are:
111+
1. [Safe method](https://fetch.spec.whatwg.org/#cors-safelisted-method): GET, POST or HEAD
112+
2. [Safe headers](https://fetch.spec.whatwg.org/#cors-safelisted-request-header) -- the only allowed custom headers are:
113113
- `Accept`,
114114
- `Accept-Language`,
115115
- `Content-Language`,
116116
- `Content-Type` with the value `application/x-www-form-urlencoded`, `multipart/form-data` or `text/plain`.
117117

118-
Any other request is considered "non-simple". For instance, a request with `PUT` method or with an `API-Key` HTTP-header does not fit the limitations.
118+
Any other request is considered "unsafe". For instance, a request with `PUT` method or with an `API-Key` HTTP-header does not fit the limitations.
119119

120-
**The essential difference is that a "simple request" can be made with a `<form>` or a `<script>`, without any special methods.**
120+
**The essential difference is that a safe request can be made with a `<form>` or a `<script>`, without any special methods.**
121121

122-
So, even a very old server should be ready to accept a simple request.
122+
So, even a very old server should be ready to accept a safe request.
123123

124124
Contrary to that, requests with non-standard headers or e.g. method `DELETE` can't be created this way. For a long time JavaScript was unable to do such requests. So an old server may assume that such requests come from a privileged source, "because a webpage is unable to send them".
125125
126-
When we try to make a non-simple request, the browser sends a special "preflight" request that asks the server -- does it agree to accept such cross-origin requests, or not?
126+
When we try to make a unsafe request, the browser sends a special "preflight" request that asks the server -- does it agree to accept such cross-origin requests, or not?
127127
128-
And, unless the server explicitly confirms that with headers, a non-simple request is not sent.
128+
And, unless the server explicitly confirms that with headers, a unsafe request is not sent.
129129
130130
Now we'll go into details.
131131

132-
## CORS for simple requests
132+
## CORS for safe requests
133133

134134
If a request is cross-origin, the browser always adds `Origin` header to it.
135135

@@ -165,7 +165,7 @@ Access-Control-Allow-Origin: https://javascript.info
165165
166166
## Response headers
167167
168-
For cross-origin request, by default JavaScript may only access so-called "simple" response headers:
168+
For cross-origin request, by default JavaScript may only access so-called "safe" response headers:
169169
170170
- `Cache-Control`
171171
- `Content-Language`
@@ -182,7 +182,7 @@ There's no `Content-Length` header in the list!
182182
This header contains the full response length. So, if we're downloading something and would like to track the percentage of progress, then an additional permission is required to access that header (see below).
183183
```
184184
185-
To grant JavaScript access to any other response header, the server must send `Access-Control-Expose-Headers` header. It contains a comma-separated list of non-simple header names that should be made accessible.
185+
To grant JavaScript access to any other response header, the server must send `Access-Control-Expose-Headers` header. It contains a comma-separated list of unsafe header names that should be made accessible.
186186
187187
For example:
188188
@@ -199,18 +199,18 @@ Access-Control-Expose-Headers: Content-Length,API-Key
199199
200200
With such `Access-Control-Expose-Headers` header, the script is allowed to read `Content-Length` and `API-Key` headers of the response.
201201
202-
## "Non-simple" requests
202+
## "Unsafe" requests
203203
204204
We can use any HTTP-method: not just `GET/POST`, but also `PATCH`, `DELETE` and others.
205205
206206
Some time ago no one could even imagine that a webpage could make such requests. So there may still exist webservices that treat a non-standard method as a signal: "That's not a browser". They can take it into account when checking access rights.
207207
208-
So, to avoid misunderstandings, any "non-simple" request -- that couldn't be done in the old times, the browser does not make such requests right away. Before it sends a preliminary, so-called "preflight" request, asking for permission.
208+
So, to avoid misunderstandings, any "unsafe" request -- that couldn't be done in the old times, the browser does not make such requests right away. Before it sends a preliminary, so-called "preflight" request, asking for permission.
209209
210210
A preflight request uses method `OPTIONS`, no body and two headers:
211211
212-
- `Access-Control-Request-Method` header has the method of the non-simple request.
213-
- `Access-Control-Request-Headers` header provides a comma-separated list of its non-simple HTTP-headers.
212+
- `Access-Control-Request-Method` header has the method of the unsafe request.
213+
- `Access-Control-Request-Headers` header provides a comma-separated list of its unsafe HTTP-headers.
214214
215215
If the server agrees to serve the requests, then it should respond with empty body, status 200 and headers:
216216
@@ -233,10 +233,10 @@ let response = await fetch('https://site.com/service.json', {
233233
});
234234
```
235235
236-
There are three reasons why the request is not simple (one is enough):
236+
There are three reasons why the request is unsafe (one is enough):
237237
- Method `PATCH`
238238
- `Content-Type` is not one of: `application/x-www-form-urlencoded`, `multipart/form-data`, `text/plain`.
239-
- "Non-simple" `API-Key` header.
239+
- "Unsafe" `API-Key` header.
240240
241241
### Step 1 (preflight request)
242242
@@ -255,7 +255,7 @@ Access-Control-Request-Headers: Content-Type,API-Key
255255
- Cross-origin special headers:
256256
- `Origin` -- the source origin.
257257
- `Access-Control-Request-Method` -- requested method.
258-
- `Access-Control-Request-Headers` -- a comma-separated list of "non-simple" headers.
258+
- `Access-Control-Request-Headers` -- a comma-separated list of "unsafe" headers.
259259
260260
### Step 2 (preflight response)
261261
@@ -284,7 +284,7 @@ If there's header `Access-Control-Max-Age` with a number of seconds, then the pr
284284
285285
### Step 3 (actual request)
286286
287-
When the preflight is successful, the browser now makes the main request. The algorithm here is the same as for simple requests.
287+
When the preflight is successful, the browser now makes the main request. The algorithm here is the same as for safe requests.
288288
289289
The main request has `Origin` header (because it's cross-origin):
290290
@@ -350,21 +350,21 @@ Please note: `Access-Control-Allow-Origin` is prohibited from using a star `*` f
350350
351351
## Summary
352352
353-
From the browser point of view, there are two kinds of cross-origin requests: "simple" and all the others.
353+
From the browser point of view, there are two kinds of cross-origin requests: "safe" and all the others.
354354
355-
[Simple requests](http://www.w3.org/TR/cors/#terminology) must satisfy the following conditions:
355+
"Safe" requests must satisfy the following conditions:
356356
- Method: GET, POST or HEAD.
357357
- Headers -- we can set only:
358358
- `Accept`
359359
- `Accept-Language`
360360
- `Content-Language`
361361
- `Content-Type` to the value `application/x-www-form-urlencoded`, `multipart/form-data` or `text/plain`.
362362
363-
The essential difference is that simple requests were doable since ancient times using `<form>` or `<script>` tags, while non-simple were impossible for browsers for a long time.
363+
The essential difference is that safe requests were doable since ancient times using `<form>` or `<script>` tags, while unsafe were impossible for browsers for a long time.
364364
365-
So, the practical difference is that simple requests are sent right away, with `Origin` header, while for the other ones the browser makes a preliminary "preflight" request, asking for permission.
365+
So, the practical difference is that safe requests are sent right away, with `Origin` header, while for the other ones the browser makes a preliminary "preflight" request, asking for permission.
366366
367-
**For simple requests:**
367+
**For safe requests:**
368368
369369
- → The browser sends `Origin` header with the origin.
370370
- ← For requests without credentials (not sent default), the server should set:
@@ -375,13 +375,13 @@ So, the practical difference is that simple requests are sent right away, with `
375375
376376
Additionally, to grant JavaScript access to any response headers except `Cache-Control`, `Content-Language`, `Content-Type`, `Expires`, `Last-Modified` or `Pragma`, the server should list the allowed ones in `Access-Control-Expose-Headers` header.
377377
378-
**For non-simple requests, a preliminary "preflight" request is issued before the requested one:**
378+
**For unsafe requests, a preliminary "preflight" request is issued before the requested one:**
379379
380380
- → The browser sends `OPTIONS` request to the same URL, with headers:
381381
- `Access-Control-Request-Method` has requested method.
382-
- `Access-Control-Request-Headers` lists non-simple requested headers.
382+
- `Access-Control-Request-Headers` lists unsafe requested headers.
383383
- ← The server should respond with status 200 and headers:
384384
- `Access-Control-Allow-Methods` with a list of allowed methods,
385385
- `Access-Control-Allow-Headers` with a list of allowed headers,
386386
- `Access-Control-Max-Age` with a number of seconds to cache permissions.
387-
- Then the actual request is sent, the previous "simple" scheme is applied.
387+
- Then the actual request is sent, the previous "safe" scheme is applied.

Diff for: 5-network/06-fetch-api/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The `mode` option is a safe-guard that prevents occasional cross-origin requests
138138
139139
- **`"cors"`** -- the default, cross-origin requests are allowed, as described in <info:fetch-crossorigin>,
140140
- **`"same-origin"`** -- cross-origin requests are forbidden,
141-
- **`"no-cors"`** -- only simple cross-origin requests are allowed.
141+
- **`"no-cors"`** -- only safe cross-origin requests are allowed.
142142
143143
This option may be useful when the URL for `fetch` comes from a 3rd-party, and we want a "power off switch" to limit cross-origin capabilities.
144144

0 commit comments

Comments
 (0)