Skip to content

Commit 7b0f9e5

Browse files
authored
Content-Length is now a CORS-safelisted response header
See [MDN](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header) and [whatwg/fetch](whatwg/fetch#626).
1 parent bf7d8bb commit 7b0f9e5

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

5-network/05-fetch-crossorigin/article.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,14 @@ For cross-origin request, by default JavaScript may only access so-called "safe"
169169

170170
- `Cache-Control`
171171
- `Content-Language`
172+
- `Content-Length`
172173
- `Content-Type`
173174
- `Expires`
174175
- `Last-Modified`
175176
- `Pragma`
176177

177178
Accessing any other response header causes an error.
178179

179-
```smart
180-
There's no `Content-Length` header in the list!
181-
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-
```
184-
185180
To grant JavaScript access to any other response header, the server must send the `Access-Control-Expose-Headers` header. It contains a comma-separated list of unsafe header names that should be made accessible.
186181

187182
For example:
@@ -190,14 +185,15 @@ For example:
190185
200 OK
191186
Content-Type:text/html; charset=UTF-8
192187
Content-Length: 12345
188+
Content-Encoding: gzip
193189
API-Key: 2c9de507f2c54aa1
194190
Access-Control-Allow-Origin: https://javascript.info
195191
*!*
196-
Access-Control-Expose-Headers: Content-Length,API-Key
192+
Access-Control-Expose-Headers: Content-Encoding,API-Key
197193
*/!*
198194
```
199195

200-
With such an `Access-Control-Expose-Headers` header, the script is allowed to read the `Content-Length` and `API-Key` headers of the response.
196+
With such an `Access-Control-Expose-Headers` header, the script is allowed to read the `Content-Encoding` and `API-Key` headers of the response.
201197

202198
## "Unsafe" requests
203199

0 commit comments

Comments
 (0)