diff --git a/5-network/05-fetch-crossorigin/1-do-we-need-origin/solution.md b/5-network/05-fetch-crossorigin/1-do-we-need-origin/solution.md index d44494e18..58f1f7d55 100644 --- a/5-network/05-fetch-crossorigin/1-do-we-need-origin/solution.md +++ b/5-network/05-fetch-crossorigin/1-do-we-need-origin/solution.md @@ -1,9 +1,9 @@ -We need `Origin`, because sometimes `Referer` is absent. For instance, when we `fetch` HTTP-page from HTTPS (access less secure from more secure), then there's no `Referer`. +Precisamos de `Origin`, porque às vezes `Referer` está ausente. Por exemplo, quando fazemos `fetch` de uma página HTTP a partir de HTTPS (acessar algo menos seguro a partir de algo mais seguro), então não há `Referer`. -The [Content Security Policy](http://en.wikipedia.org/wiki/Content_Security_Policy) may forbid sending a `Referer`. +A [Content Security Policy](http://en.wikipedia.org/wiki/Content_Security_Policy) pode proibir o envio de um `Referer`. -As we'll see, `fetch` has options that prevent sending the `Referer` and even allow to change it (within the same site). +Como vamos ver, `fetch` tem opções que impedem o envio do `Referer` e até permitem alterá-lo (dentro do mesmo site). -By specification, `Referer` is an optional HTTP-header. +Pela especificação, `Referer` é um cabeçalho HTTP opcional. -Exactly because `Referer` is unreliable, `Origin` was invented. The browser guarantees correct `Origin` for cross-origin requests. +Exatamente porque `Referer` não é confiável, `Origin` foi inventado. O navegador garante um `Origin` correto para requisições cross-origin. diff --git a/5-network/05-fetch-crossorigin/1-do-we-need-origin/task.md b/5-network/05-fetch-crossorigin/1-do-we-need-origin/task.md index fb8142a3b..1855e1626 100644 --- a/5-network/05-fetch-crossorigin/1-do-we-need-origin/task.md +++ b/5-network/05-fetch-crossorigin/1-do-we-need-origin/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Why do we need Origin? +# Por que precisamos de Origin? -As you probably know, there's HTTP-header `Referer`, that usually contains an url of the page which initiated a network request. +Como você provavelmente sabe, existe o cabeçalho HTTP `Referer`, que normalmente contém a url da página que iniciou uma requisição de rede. -For instance, when fetching `http://google.com` from `http://javascript.info/some/url`, the headers look like this: +Por exemplo, ao buscar `http://google.com` a partir de `http://javascript.info/some/url`, os cabeçalhos se parecem com isto: ``` Accept: */* @@ -20,9 +20,9 @@ Referer: http://javascript.info/some/url */!* ``` -As you can see, both `Referer` and `Origin` are present. +Como você pode ver, tanto `Referer` quanto `Origin` estão presentes. -The questions: +As perguntas: -1. Why `Origin` is needed, if `Referer` has even more information? -2. Is it possible that there's no `Referer` or `Origin`, or is it incorrect? +1. Por que `Origin` é necessário, se `Referer` tem até mais informação? +2. É possível que não haja `Referer` ou `Origin`, ou isso está incorreto? diff --git a/5-network/05-fetch-crossorigin/article.md b/5-network/05-fetch-crossorigin/article.md index 4420f43c7..904bc95c2 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. +Se enviarmos uma requisição `fetch` para outro site, provavelmente ela vai falhar. -For instance, let's try fetching `http://example.com`: +Por exemplo, vamos tentar buscar `http://example.com`: ```js run async try { @@ -12,39 +12,39 @@ try { } ``` -Fetch fails, as expected. +O fetch falha, como esperado. -The core concept here is *origin* -- a domain/port/protocol triplet. +O conceito central aqui é *origin* -- uma tripla domínio/porta/protocolo. -Cross-origin requests -- those sent to another domain (even a subdomain) or protocol or port -- require special headers from the remote side. +Requisições cross-origin -- aquelas enviadas para outro domínio (até mesmo um subdomínio) ou protocolo ou porta -- exigem cabeçalhos especiais do lado remoto. -That policy is called "CORS": Cross-Origin Resource Sharing. +Essa política é chamada de "CORS": Cross-Origin Resource Sharing. -## Why is CORS needed? A brief history +## Por que o CORS é necessário? Um breve histórico -CORS exists to protect the internet from evil hackers. +O CORS existe para proteger a internet de hackers mal-intencionados. -Seriously. Let's make a very brief historical digression. +Sério. Vamos fazer uma breve digressão histórica. -**For many years a script from one site could not access the content of another site.** +**Por muitos anos, um script de um site não conseguia acessar o conteúdo de outro site.** -That simple, yet powerful rule was a foundation of the internet security. E.g. an evil script from website `hacker.com` could not access the user's mailbox at website `gmail.com`. People felt safe. +Essa regra simples, mas poderosa, era um fundamento da segurança da internet. Por exemplo, um script mal-intencionado do site `hacker.com` não conseguia acessar a caixa de e-mail do usuário no site `gmail.com`. As pessoas se sentiam seguras. -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. +O JavaScript também não tinha nenhum método especial para realizar requisições de rede naquela época. Era uma linguagem de brinquedo para decorar uma página web. -But web developers demanded more power. A variety of tricks were invented to work around the limitation and make requests to other websites. +Mas os desenvolvedores web exigiam mais poder. Uma variedade de truques foi inventada para contornar a limitação e fazer requisições para outros sites. -### Using forms +### Usando formulários -One way to communicate with another server was to submit a `