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
cache:"default", // no-store, reload, no-cache, force-cache, or only-if-cached
31
31
redirect:"follow", // manual, error
32
-
integrity:"", // a hash, like "sha256-abcdef1234567890"
32
+
integrity:"", // a hash, tipo "sha256-abcdef1234567890"
33
33
keepalive:false, // true
34
-
signal:undefined, // AbortController to abort request
34
+
signal:undefined, // AbortController per annullare la richiesta
35
35
window:window// null
36
36
});
37
37
```
38
38
39
-
An impressive list, right?
39
+
Una lista impressionante, giusto?
40
40
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>.
42
42
43
-
The`signal`option is covered in <info:fetch-abort>.
43
+
L'opzione`signal`è affrontata in <info:fetch-abort>.
44
44
45
-
Now let's explore the remaining capabilities.
45
+
Adesso andiamo ad esplorare le rimanenti funzionalità.
46
46
47
47
## referrer, referrerPolicy
48
48
49
-
These options govern how`fetch`sets the HTTP `Referer` header.
49
+
Queste opzioni gestiscono come`fetch`imposta l'header HTTP `Referer`.
50
50
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.
52
52
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.**
54
54
55
-
To send no referer, set an empty string:
55
+
Per non inviare alcun referer, impostare una stringa vuota:
56
56
```js
57
57
fetch('/page', {
58
58
*!*
59
-
referrer:""//no Referer header
59
+
referrer:""//nessun header Referer
60
60
*/!*
61
61
});
62
62
```
63
63
64
-
To set another url within the current origin:
64
+
Per impostare un altro url, all'interno dello stesso *origin* di quello attuale:
65
65
66
66
```js
67
67
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
70
70
*!*
71
71
referrer:"https://javascript.info/anotherpage"
72
72
*/!*
73
73
});
74
74
```
75
75
76
-
**The`referrerPolicy`option sets general rules for`Referer`.**
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).
83
83
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.
85
85
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/):
87
87
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.
96
96
97
-
Here's a table with all combinations:
97
+
Ecco una tabella con tutte le combinazioni:
98
98
99
99
| Value | To same origin | To another origin | HTTPS→HTTP |
@@ -107,13 +107,13 @@ Here's a table with all combinations:
107
107
|`"strict-origin-when-cross-origin"`| full | origin | - |
108
108
|`"unsafe-url"`| full | full | full |
109
109
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.
111
111
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`).
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`.
126
126
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).
128
128
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.
131
131
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">`.
133
133
```
134
134
135
135
## mode
136
136
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:
138
138
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.
142
142
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.
144
144
145
145
## credentials
146
146
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.
148
148
149
149
- **`"same-origin"`** -- the default, don't send for cross-origin requests,
150
150
- **`"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