From e39603896e1a67837c46cd932810d8adb3a2c998 Mon Sep 17 00:00:00 2001 From: Diego Mascheroni Date: Mon, 5 Oct 2020 22:56:05 -0300 Subject: [PATCH 01/22] se actualiza con la version en ingles --- 5-network/05-fetch-crossorigin/article.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/5-network/05-fetch-crossorigin/article.md b/5-network/05-fetch-crossorigin/article.md index 36c57aed4..0c1429697 100644 --- a/5-network/05-fetch-crossorigin/article.md +++ b/5-network/05-fetch-crossorigin/article.md @@ -214,6 +214,7 @@ A preflight request uses method `OPTIONS`, no body and two headers: If the server agrees to serve the requests, then it should respond with empty body, status 200 and headers: +- `Access-Control-Allow-Origin` must be either `*` or the requesting origin, such as `https://javascript.info`, to allow it. - `Access-Control-Allow-Methods` must have the allowed method. - `Access-Control-Allow-Headers` must have a list of allowed headers. - 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. @@ -259,15 +260,19 @@ Access-Control-Request-Headers: Content-Type,API-Key ### Step 2 (preflight response) The server should respond with status 200 and headers: +- `Access-Control-Allow-Origin: https://javascript.info` - `Access-Control-Allow-Methods: PATCH` - `Access-Control-Allow-Headers: Content-Type,API-Key`. That allows future communication, otherwise an error is triggered. -If the server expects other methods and headers in the future, it makes sense to allow them in advance by adding to the list: +If the server expects other methods and headers in the future, it makes sense to allow them in advance by adding to the list. + +For example, this response also allows `PUT`, `DELETE` and additional headers: ```http 200 OK +Access-Control-Allow-Origin: https://javascript.info Access-Control-Allow-Methods: PUT,PATCH,DELETE Access-Control-Allow-Headers: API-Key,Content-Type,If-Modified-Since,Cache-Control Access-Control-Max-Age: 86400 @@ -275,7 +280,7 @@ Access-Control-Max-Age: 86400 Now the browser can see that `PATCH` is in `Access-Control-Allow-Methods` and `Content-Type,API-Key` are in the list `Access-Control-Allow-Headers`, so it sends out the main request. -Besides, the preflight response is cached for time, specified by `Access-Control-Max-Age` header (86400 seconds, one day), so subsequent requests will not cause a preflight. Assuming that they fit the cached allowances, they will be sent directly. +If there's header `Access-Control-Max-Age` with a number of seconds, then the preflight permissions are cached for the given time. The response above will be cached for 86400 seconds (one day). Within this timeframe, subsequent requests will not cause a preflight. Assuming that they fit the cached allowances, they will be sent directly. ### Step 3 (actual request) @@ -329,7 +334,7 @@ fetch('http://another.com', { }); ``` -Now `fetch` sends cookies originating from `another.com` without request to that site. +Now `fetch` sends cookies originating from `another.com` with request to that site. If the server agrees to accept the request *with credentials*, it should add a header `Access-Control-Allow-Credentials: true` to the response, in addition to `Access-Control-Allow-Origin`. From ca6607b3c4570e60eb7751e120bc4f81503dc91d Mon Sep 17 00:00:00 2001 From: Diego Mascheroni Date: Fri, 16 Oct 2020 11:07:06 -0300 Subject: [PATCH 02/22] traduccion parcial --- 5-network/05-fetch-crossorigin/article.md | 104 +++++++++++----------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/5-network/05-fetch-crossorigin/article.md b/5-network/05-fetch-crossorigin/article.md index 0c1429697..505e6b504 100644 --- a/5-network/05-fetch-crossorigin/article.md +++ b/5-network/05-fetch-crossorigin/article.md @@ -1,8 +1,8 @@ # Fetch: Cross-Origin Requests -If we send a `fetch` request to another web-site, it will probably fail. +Si enviamos una petición `fetch` hacia otro sitio seguramente fallará. -For instance, let's try fetching `http://example.com`: +Pro ejemplo, probemos realizar una petición a `http://example.com`: ```js run async try { @@ -12,39 +12,39 @@ try { } ``` -Fetch fails, as expected. +El método fetch falla, tal como lo esperabamos. -The core concept here is *origin* -- a domain/port/protocol triplet. +El concepto clave aquí es *el origen* (*origin*), triple combinación de dominio/puerto/protocolo. -Cross-origin requests -- those sent to another domain (even a subdomain) or protocol or port -- require special headers from the remote side. +Las solicitudes de origen cruzado `Cross-origin requests`, tales que son enviadas hacia otro dominio (incluso subdominio), protocolo o puerto, requieren de unas cabeceras especiales desde el sitio remoto. -That policy is called "CORS": Cross-Origin Resource Sharing. +Esta política es denominada "CORS", por sus siglas en inglés Cross-Origin Resource Sharing. -## Why is CORS needed? A brief history +## ¿Por que CORS es necesario?, Una breve historia -CORS exists to protect the internet from evil hackers. +CORS exíste para protejer Internet de los malvados hackers. -Seriously. Let's make a very brief historical digression. +En verdad... Déjame contarte un breve resumen de esta historia. -**For many years a script from one site could not access the content of another site.** +**Durante muchos años un script de un sitio no podía acceder al contenido de otro sitio.** -That simple, yet powerful rule was a foundation of the internet security. E.g. an evil script from website `hacker.com` could not access user's mailbox at website `gmail.com`. People felt safe. +Esta simple, pero poderosa regla, fue parte fundacional de la seguridad de Internet. Ej: Un script malisioso desde el sitio `hacker.com` no podía acceder a la casilla de correo en el sitio `gmail.com`. La gente se podía sentir segura. -JavaScript also did not have any special methods to perform network requests at that time. It was a toy language to decorate a web page. +Así mismo en ese momento, JavaScript no tenía ningún método especial para realizar solicitudes de red. Simplemente era un lenguaje juguete para decorar páginas web. -But web developers demanded more power. A variety of tricks were invented to work around the limitation and make requests to other websites. +Pero los desarrolladores web demandaron más poder. Una variedad de trucos fueron inventados para poder pasar por alto las limitaciones, y realizar solicitudes a otros sitios. -### Using forms +### Utilizando formularios -One way to communicate with another server was to submit a `
` there. People submitted it into ` */!* - + *!* */!* @@ -52,36 +52,36 @@ One way to communicate with another server was to submit a `` there. Peopl
``` -So, it was possible to make a GET/POST request to another site, even without networking methods, as forms can send data anywhere. But as it's forbidden to access the content of an `