Skip to content

Commit e7a7a6d

Browse files
prima parte
1 parent 25dbab4 commit e7a7a6d

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

5-network/06-fetch-api/article.md

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,100 @@
11

2-
# Fetch API
2+
# API Fetch
33

4-
So far, we know quite a bit about `fetch`.
4+
Arrivati fin qui, sappiamo un bel po' di cose su `fetch`.
55

6-
Let's see the rest of API, to cover all its abilities.
6+
Guardiamo il resto dell'API, per approfindirne le potenzialità.
77

88
```smart
9-
Please note: most of these options are used rarely. You may skip this chapter and still use `fetch` well.
9+
Nota bene: la maggioranza di queste opzioni viene usata raremente. Potresti saltare questo capitolo e comunque continuare ad usare bene `fetch`.
1010
11-
Still, it's good to know what `fetch` can do, so if the need arises, you can return and read the details.
11+
Ma ancora una volta, è una cosa buona sapere cosa fa `fetch`, e inoltre se dovessero sorgere necessità, possiamo tornare e leggere i dettagli.
1212
```
1313

14-
Here's the full list of all possible `fetch` options with their default values (alternatives in comments):
14+
Ecco la lista completa di tutte le opzioni possibili per `fetch` con i loro valorri predefiniti (valori alternativi nei commenti):
1515

1616
```js
1717
let promise = fetch(url, {
1818
method: "GET", // POST, PUT, DELETE, etc.
1919
headers: {
20-
// the content type header value is usually auto-set
21-
// depending on the request body
20+
// l'header del content type solitamente è auto impostato
21+
// a seconda del corpo della richiesta
2222
"Content-Type": "text/plain;charset=UTF-8"
2323
},
24-
body: undefined // string, FormData, Blob, BufferSource, or URLSearchParams
25-
referrer: "about:client", // or "" to send no Referer header,
26-
// or an url from the current origin
24+
body: undefined // string, FormData, Blob, BufferSource, o URLSearchParams
25+
referrer: "about:client", // oppure "" per inviare un header di Referer nullo,
26+
// o un url dalla *origin* attuale
2727
referrerPolicy: "no-referrer-when-downgrade", // no-referrer, origin, same-origin...
2828
mode: "cors", // same-origin, no-cors
2929
credentials: "same-origin", // omit, include
3030
cache: "default", // no-store, reload, no-cache, force-cache, or only-if-cached
3131
redirect: "follow", // manual, error
32-
integrity: "", // a hash, like "sha256-abcdef1234567890"
32+
integrity: "", // a hash, tipo "sha256-abcdef1234567890"
3333
keepalive: false, // true
34-
signal: undefined, // AbortController to abort request
34+
signal: undefined, // AbortController per annullare la richiesta
3535
window: window // null
3636
});
3737
```
3838

39-
An impressive list, right?
39+
Una lista impressionante, giusto?
4040

41-
We fully covered `method`, `headers` and `body` in the chapter <info:fetch>.
41+
Abbiamo affrontato per bene `method`, `headers` e `body` nel capitolo <info:fetch>.
4242

43-
The `signal` option is covered in <info:fetch-abort>.
43+
L'opzione `signal` è affrontata in <info:fetch-abort>.
4444

45-
Now let's explore the remaining capabilities.
45+
Adesso andiamo ad esplorare le rimanenti funzionalità.
4646

4747
## referrer, referrerPolicy
4848

49-
These options govern how `fetch` sets the HTTP `Referer` header.
49+
Queste opzioni gestiscono come `fetch` imposta l'header HTTP `Referer`.
5050

51-
Usually that header is set automatically and contains the url of the page that made the request. In most scenarios, it's not important at all, sometimes, for security purposes, it makes sense to remove or shorten it.
51+
Solitamente questo header viene impostato automaticamente e contiene l'URL della pagina che ha eseguito la richiesta. Nella maggioranza degli scenari, non ha nessuna importanza, ma qualche volta per ragioni di sicurezza ha senso rimuoverlo o abbreviarlo.
5252

53-
**The `referrer` option allows to set any `Referer` (within the current origin) or remove it.**
53+
**L'opzione `referrer` permette di impostare qualunque `Referer` (all'interno dell'origine attuale) o di rimuoverlo.**
5454

55-
To send no referer, set an empty string:
55+
Per non inviare alcun referer, impostare una stringa vuota:
5656
```js
5757
fetch('/page', {
5858
*!*
59-
referrer: "" // no Referer header
59+
referrer: "" // nessun header Referer
6060
*/!*
6161
});
6262
```
6363

64-
To set another url within the current origin:
64+
Per impostare un altro url, all'interno dello stesso *origin* di quello attuale:
6565

6666
```js
6767
fetch('/page', {
68-
// assuming we're on https://javascript.info
69-
// we can set any Referer header, but only within the current origin
68+
// assumendo che siamo su https://javascript.info
69+
// possiamo impostare qualunque header Referer, a patto che faccia parte dello stesso origin
7070
*!*
7171
referrer: "https://javascript.info/anotherpage"
7272
*/!*
7373
});
7474
```
7575

76-
**The `referrerPolicy` option sets general rules for `Referer`.**
76+
**L'opzione `referrerPolicy` imposta regole generali per `Referer`.**
7777

78-
Requests are split into 3 types:
78+
Le richieste sono divise in 3 tipi:
7979

80-
1. Request to the same origin.
81-
2. Request to another origin.
82-
3. Request from HTTPS to HTTP (from safe to unsafe protocol).
80+
1. Richieste alla stessa origine.
81+
2. Richieste ad un altra origine.
82+
3. Richieste da HTTPS ad HTTP (da protocollo sicuro a non sicuro).
8383

84-
Unlike the `referrer` option that allows to set the exact `Referer` value, `referrerPolicy` tells the browser general rules for each request type.
84+
Diversamente dall'opzione `referrer` che permette di impostare l'esatto valore di `Referer`, `referrerPolicy` comunica al browser le regole generali per ogni tipo di richiesta.
8585

86-
Possible values are described in the [Referrer Policy specification](https://w3c.github.io/webappsec-referrer-policy/):
86+
I valori possibili vengono descritti nelle [Specifiche di Referrer Policy](https://w3c.github.io/webappsec-referrer-policy/):
8787

88-
- **`"no-referrer-when-downgrade"`** -- the default value: full `Referer` is always sent, unless we send a request from HTTPS to HTTP (to the less secure protocol).
89-
- **`"no-referrer"`** -- never send `Referer`.
90-
- **`"origin"`** -- only send the origin in `Referer`, not the full page URL, e.g. only `http://site.com` instead of `http://site.com/path`.
91-
- **`"origin-when-cross-origin"`** -- send the full `Referer` to the same origin, but only the origin part for cross-origin requests (as above).
92-
- **`"same-origin"`** -- send the full `Referer` to the same origin, but no `Referer` for cross-origin requests.
93-
- **`"strict-origin"`** -- send only the origin, not the `Referer` for HTTPS→HTTP requests.
94-
- **`"strict-origin-when-cross-origin"`** -- for same-origin send the full `Referer`, for cross-origin send only the origin, unless it's HTTPS→HTTP request, then send nothing.
95-
- **`"unsafe-url"`** -- always send the full url in `Referer`, even for HTTPS→HTTP requests.
88+
- **`"no-referrer-when-downgrade"`** -- il valore predefinito: viene sempre inviato il `Referer` completo, a meno che non inviamo una richiesta da HTTPS ad HTTP (verso il protocollo meno sicuro).
89+
- **`"no-referrer"`** -- non invia mai il `Referer`.
90+
- **`"origin"`** -- invia solamente l'origin nel `Referer`, non l'URL completo della pagina, ad esempio solo `http://site.com` invece di `http://site.com/path`.
91+
- **`"origin-when-cross-origin"`** -- invia il `Referer` completo per richiesta alla stessa origin, ma solamente l'origin per richieste cross-origin (come sopra).
92+
- **`"same-origin"`** -- invia il `Referer` completo per richieste verso la stessa origin, ma nessun `Referer` per richieste cross-origin.
93+
- **`"strict-origin"`** -- invia solamente l'origin, non il `Referer` per richieste HTTPS→HTTP.
94+
- **`"strict-origin-when-cross-origin"`** -- per richieste same-origin invia il `Referer` completo, per quelle cross-origin invia solo l'origin, a meno che non sia una richiesta HTTPS→HTTP request, per le quali non invierebbe nulla.
95+
- **`"unsafe-url"`** -- invia sempre l'url completo nel `Referer`, anche per richieste HTTPS→HTTP.
9696

97-
Here's a table with all combinations:
97+
Ecco una tabella con tutte le combinazioni:
9898

9999
| Value | To same origin | To another origin | HTTPS→HTTP |
100100
|-------|----------------|-------------------|------------|
@@ -107,13 +107,13 @@ Here's a table with all combinations:
107107
| `"strict-origin-when-cross-origin"` | full | origin | - |
108108
| `"unsafe-url"` | full | full | full |
109109

110-
Let's say we have an admin zone with a URL structure that shouldn't be known from outside of the site.
110+
Immaginiamo di avere un'are di amministrazione con una struttura URL che dovrebbe rimanere nascosta all'esterno del sito.
111111

112-
If we send a `fetch`, then by default it always sends the `Referer` header with the full url of our page (except when we request from HTTPS to HTTP, then no `Referer`).
112+
Se inviamo un `fetch`, per impostazione predefinita invierà sempre l'header `Referer` con l'url completo della nostra pagina (eccetto quando eseguiamo le chiamate da HTTPS ad HTTP, in cui non ci sarà `Referer`).
113113

114-
E.g. `Referer: https://javascript.info/admin/secret/paths`.
114+
Ad esempio `Referer: https://javascript.info/admin/secret/paths`.
115115

116-
If we'd like other websites know only the origin part, not the URL-path, we can set the option:
116+
Se volessimo che gli altri siti conoscessero solamente la parte dell'origin, e non l'URL-path, possiamo impostare l'opzione:
117117

118118
```js
119119
fetch('https://another.com/page', {
@@ -122,29 +122,29 @@ fetch('https://another.com/page', {
122122
});
123123
```
124124

125-
We can put it to all `fetch` calls, maybe integrate into JavaScript library of our project that does all requests and uses `fetch` inside.
125+
Possiamo inserirlo in tutte le chiamate `fetch`, magari integrandolo dentro una libreria JavaScript del nostro progetto che effettuerebbe tutte le richieste usando `fetch`.
126126

127-
Its only difference compared to the default behavior is that for requests to another origin `fetch` sends only the origin part of the URL (e.g. `https://javascript.info`, without path). For requests to our origin we still get the full `Referer` (maybe useful for debugging purposes).
127+
La differenza con il comportamente predefinito è che per richieste verso altri origin `fetch` invia solamente la parte origin dell'URL (ad esempio `https://javascript.info`, senza il percorso). Per richieste verso la nostra origin otteniamo ancora il `Referer` completo (utile forse a scopo di debugging).
128128

129-
```smart header="Referrer policy is not only for `fetch`"
130-
Referrer policy, described in the [specification](https://w3c.github.io/webappsec-referrer-policy/), is not just for `fetch`, but more global.
129+
```smart header="Referrer policy non serve solo per `fetch`"
130+
La referrer policy, descritta nelle [specifiche](https://w3c.github.io/webappsec-referrer-policy/), non coinvolge solo `fetch`, ma è più generico.
131131

132-
In particular, it's possible to set the default policy for the whole page using the `Referrer-Policy` HTTP header, or per-link, with `<a rel="noreferrer">`.
132+
In particolare, è possibile impostare la policy predefinita per l'intera pagina usando l'header HTTP `Referrer-Policy`, o a livello di link, tramite `<a rel="noreferrer">`.
133133
```
134134
135135
## mode
136136
137-
The `mode` option is a safe-guard that prevents occasional cross-origin requests:
137+
L'opzione `mode` è una salvaguardia che previene richieste cross-origin occasionali:
138138
139-
- **`"cors"`** -- the default, cross-origin requests are allowed, as described in <info:fetch-crossorigin>,
140-
- **`"same-origin"`** -- cross-origin requests are forbidden,
141-
- **`"no-cors"`** -- only safe cross-origin requests are allowed.
139+
- **`"cors"`** -- il comportamento predefinito, le richieste cross-origin sono permesse, come descritto in <info:fetch-crossorigin>,
140+
- **`"same-origin"`** -- le richeiste cross-origin sono vietate,
141+
- **`"no-cors"`** -- vengono permesse solamante richieste cross-origin sicure.
142142
143-
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.
143+
Questa opzione può essere utile quando l'URL per il `fetch` su terze parti, e vogliamo un "pulsante di spegnimento" per limitare le funzionalità cross-orgin.
144144
145145
## credentials
146146
147-
The `credentials` option specifies whether `fetch` should send cookies and HTTP-Authorization headers with the request.
147+
L'opzione `credentials` specifica se `fetch` deve mandare i cookies e gli headers di HTTP-Authorization insieme alla richiesta.
148148
149149
- **`"same-origin"`** -- the default, don't send for cross-origin requests,
150150
- **`"include"`** -- always send, requires `Accept-Control-Allow-Credentials` from cross-origin server in order for JavaScript to access the response, that was covered in the chapter <info:fetch-crossorigin>,

0 commit comments

Comments
 (0)