You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 5-network/05-fetch-crossorigin/article.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -174,15 +174,15 @@ For cross-origin request, by default JavaScript may only access so-called "simpl
174
174
- `Last-Modified`
175
175
- `Pragma`
176
176
177
-
Any other response header is forbidden.
177
+
Accessing any other response header causes an error.
178
178
179
179
```smart header="Please note: no `Content-Length`"
180
180
Please note: there's no `Content-Length` header in the list!
181
181
182
182
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).
183
183
```
184
184
185
-
To grant JavaScript access to any other response header, the server must list it in the `Access-Control-Expose-Headers` header.
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.
With such `Access-Control-Expose-Headers` header, the script is allowed to access `Content-Length` and `API-Key` headers of the response.
201
-
200
+
With such `Access-Control-Expose-Headers` header, the script is allowed to read `Content-Length` and `API-Key` headers of the response.
202
201
203
202
## "Non-simple" requests
204
203
@@ -208,14 +207,15 @@ Some time ago no one could even assume that a webpage is able to do such request
208
207
209
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.
210
209
211
-
A preflight request uses method `OPTIONS` and has no body.
212
-
- `Access-Control-Request-Method` header has the requested method.
210
+
A preflight request uses method `OPTIONS`, no body and two headers:
211
+
212
+
- `Access-Control-Request-Method` header has the method of a non-simple request.
213
213
- `Access-Control-Request-Headers` header provides a comma-separated list of non-simple HTTP-headers.
214
214
215
-
If the server agrees to serve the requests, then it should respond with status 200, without body.
215
+
If the server agrees to serve the requests, then it should respond with empty body, status 200 and headers:
216
216
217
-
- The response header `Access-Control-Allow-Methods` must have the allowed method.
218
-
- The response header `Access-Control-Allow-Headers` must have a list of allowed headers.
217
+
- `Access-Control-Allow-Methods` must have the allowed method.
218
+
- `Access-Control-Allow-Headers` must have a list of allowed headers.
219
219
- Additionally, the header `Access-Control-Max-Age` may specify a number of seconds to cache the permissions. So the browser won't have to send a preflight for subsequent requests that satisfy given permissions.
0 commit comments