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
Vrací dekódovaný obsah těla HTTP požadavku na základě hlavičky `Content-Type`.
190
+
191
+
```php
192
+
// Pro Content-Type: application/json
193
+
$data = $httpRequest->getDecodedBody();
194
+
echo $data->name; // přístup k JSON vlastnostem
195
+
196
+
// Pro Content-Type: application/x-www-form-urlencoded
197
+
$data = $httpRequest->getDecodedBody(); // stejné jako $_POST
198
+
```
199
+
200
+
Aktuálně podporuje pouze `application/json` a `application/x-www-form-urlencoded`. Jiné typy obsahu vyvolají výjimku.
201
+
202
+
203
+
getOrigin(): ?UrlImmutable .[method]
204
+
------------------------------------
205
+
Vrací origin (počátek), ze kterého požadavek přišel. Origin se skládá ze schématu (protokolu), hostname a portu - například `https://example.com:8080`. Vrací `null`, pokud hlavička origin není přítomna nebo je nastavena na `'null'`.
206
+
207
+
```php
208
+
$origin = $httpRequest->getOrigin();
209
+
echo $origin; // https://example.com:8080
210
+
echo $origin?->getHost(); // example.com
211
+
```
212
+
213
+
Prohlížeč posílá hlavičku `Origin` v následujících případech:
214
+
- Požadavky mezi doménami (AJAX volání na jinou doménu)
215
+
- POST, PUT, DELETE a další modifikující požadavky
216
+
- Požadavky provedené pomocí Fetch API
217
+
218
+
Prohlížeč NEPOSÍLÁ hlavičku `Origin` při:
219
+
- Běžných GET požadavcích na stejnou doménu (navigace v rámci téže domény)
220
+
- Přímé navigaci zadáním URL do adresního řádku
221
+
- Požadavcích z jiných klientů než prohlížeče (pokud není ručně přidána)
222
+
223
+
.[note]
224
+
Na rozdíl od hlavičky `Referer` obsahuje `Origin` pouze schéma, host a port - nikoli celou cestu URL. To ji činí vhodnější pro bezpečnostní kontroly při zachování soukromí uživatele. Hlavička `Origin` se primárně používá pro validaci [CORS |nette:glossary#Cross-Origin Resource Sharing (CORS)] (Cross-Origin Resource Sharing).
225
+
226
+
187
227
detectLanguage(array $langs): ?string .[method]
188
228
-----------------------------------------------
189
229
Detekuje jazyk. Jako parametr `$lang` předáme pole s jazyky, které aplikace podporuje, a ona vrátí ten, který by viděl návštěvníkův prohlížeč nejraději. Nejsou to žádná kouzla, jen se využívá hlavičky `Accept-Language`. Pokud nedojde k žádné shodě, vrací `null`.
Vrací cestu k dočasné lokaci uploadovaného souboru. V případě, že upload nebyl úspěšný, vrací `''`.
390
430
391
431
432
+
__toString(): string .[method]
433
+
------------------------------
434
+
Vrací cestu k dočasnému umístění nahraného souboru. To umožňuje objekt `FileUpload` použít přímo jako řetězec.
435
+
436
+
392
437
isImage(): bool .[method]
393
438
-------------------------
394
439
Vrací `true`, pokud nahraný soubor je obrázek ve formátu JPEG, PNG, GIF, WebP nebo AVIF. Detekce probíhá na základě jeho signatury a neověřuje se integrita celého souboru. Zda není obrázek poškozený lze zjistit například pokusem o jeho [načtení |#toImage].
Převede URL do kanonického tvaru. To zahrnuje například seřazení parametrů v query stringu podle abecedy, převod hostname na malá písmena a odstranění nadbytečných znaků.
Returns the decoded content of the HTTP request body based on the `Content-Type` header.
190
+
191
+
```php
192
+
// For Content-Type: application/json
193
+
$data = $httpRequest->getDecodedBody();
194
+
echo $data->name; // access JSON properties
195
+
196
+
// For Content-Type: application/x-www-form-urlencoded
197
+
$data = $httpRequest->getDecodedBody(); // same as $_POST
198
+
```
199
+
200
+
Currently supports only `application/json` and `application/x-www-form-urlencoded`. Other content types will throw an exception.
201
+
202
+
203
+
getOrigin(): ?UrlImmutable .[method]
204
+
------------------------------------
205
+
Returns the origin from which the request came. An origin consists of the scheme (protocol), hostname, and port - for example, `https://example.com:8080`. Returns `null` if the origin header is not present or is set to `'null'`.
206
+
207
+
```php
208
+
$origin = $httpRequest->getOrigin();
209
+
echo $origin; // https://example.com:8080
210
+
echo $origin?->getHost(); // example.com
211
+
```
212
+
213
+
The browser sends the `Origin` header in the following cases:
214
+
- Cross-origin requests (AJAX calls to a different domain)
215
+
- POST, PUT, DELETE, and other modifying requests
216
+
- Requests made using the Fetch API
217
+
218
+
The browser does NOT send the `Origin` header for:
219
+
- Regular GET requests to the same domain (same-origin navigation)
220
+
- Direct navigation by typing a URL into the address bar
221
+
- Requests from non-browser clients
222
+
223
+
.[note]
224
+
Unlike the `Referer` header, `Origin` contains only the scheme, host, and port - not the full URL path. This makes it more suitable for security checks while preserving user privacy. The `Origin` header is primarily used for [CORS |nette:glossary#Cross-Origin Resource Sharing (CORS)] (Cross-Origin Resource Sharing) validation.
225
+
226
+
187
227
detectLanguage(array $langs): ?string .[method]
188
228
-----------------------------------------------
189
229
Detects the language. Pass an array of languages supported by the application as the `$langs` parameter, and it will return the one preferred by the visitor's browser. It's not magic; it just uses the `Accept-Language` header. If no match is found, it returns `null`.
Returns the path to the temporary location of the uploaded file. If the upload was not successful, it returns `''`.
390
430
391
431
432
+
__toString(): string .[method]
433
+
------------------------------
434
+
Returns the path to the temporary location of the uploaded file. This allows the `FileUpload` object to be used directly as a string.
435
+
436
+
392
437
isImage(): bool .[method]
393
438
-------------------------
394
439
Returns `true` if the uploaded file is a JPEG, PNG, GIF, WebP, or AVIF image. Detection is based on its signature and does not verify the integrity of the entire file. Whether an image is corrupted can be determined, for example, by trying to [load it |#toImage].
Copy file name to clipboardExpand all lines: http/en/response.texy
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -34,9 +34,9 @@ isSent(): bool .[method]
34
34
Returns whether headers have already been sent from the server to the browser, meaning it is no longer possible to send headers or change the status code.
35
35
36
36
37
-
setHeader(string $name, string $value) .[method]
38
-
------------------------------------------------
39
-
Sends an HTTP header and **overwrites** a previously sent header of the same name.
37
+
setHeader(string $name, ?string $value) .[method]
38
+
-------------------------------------------------
39
+
Sends an HTTP header and **overwrites** a previously sent header of the same name. If `$value` is `null`, the header will be removed.
Converts the URL to canonical form. This includes, for example, sorting the parameters in the query string alphabetically, converting the hostname to lowercase, and removing redundant characters.
Nette Framework **automaticky chrání formuláře a signály v presenterech** před tímto typem útoku. A to tím, že zabraňuje jejich odeslání či vyvolání z jiné domény.
37
37
38
38
39
+
Cross-Origin Resource Sharing (CORS)
40
+
------------------------------------
41
+
CORS je bezpečnostní mechanismus, který umožňuje webové stránce provádět JavaScriptové požadavky na jinou doménu, než ze které byla stránka načtena. Bez CORS prohlížeče takové požadavky z bezpečnostních důvodů blokují.
42
+
43
+
Například pokud vaše webová stránka běží na `https://myapp.com` a pokusí se pomocí JavaScriptu (AJAX, Fetch API) načíst data z `https://api.example.com`, prohlížeč ověří, zda API server tento požadavek mezi doménami povoluje. API server musí odpovědět speciálními HTTP hlavičkami, jako je `Access-Control-Allow-Origin: https://myapp.com`, aby udělil povolení.
44
+
45
+
39
46
Dependency Injection
40
47
--------------------
41
48
Dependency Injection (DI) je návrhový vzor, který říká, jak oddělit vytváření objektů od jejich závislostí. Tedy že třída není zodpovědná za vytváření nebo inicializaci svých závislostí, ale místo toho jsou jí tyto závislosti poskytovány externím kódem (tím může i [DI kontejner |#Dependency Injection kontejner]). Výhoda spočívá v tom, že umožňuje větší flexibilitu kódu, lepší srozumitelnost a snazší testování aplikace, protože závislosti jsou snadno nahraditelné a izolované od ostatních částí kódu. Více v kapitole [Co je Dependency Injection? |dependency-injection:introduction]
Copy file name to clipboardExpand all lines: nette/en/glossary.texy
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,13 @@ A Cross-Site Request Forgery attack involves the attacker luring a victim to a p
36
36
Nette Framework **automatically protects forms and signals in presenters** against this type of attack by preventing them from being submitted or triggered from another domain.
37
37
38
38
39
+
Cross-Origin Resource Sharing (CORS)
40
+
------------------------------------
41
+
CORS is a security mechanism that allows a web page to make JavaScript requests to a different domain than the one from which the page was loaded. Without CORS, browsers block such requests for security reasons.
42
+
43
+
For example, if your website runs at `https://myapp.com` and tries to fetch data from `https://api.example.com` using JavaScript (AJAX, Fetch API), the browser will check if the API server allows this cross-origin request. The API server must respond with special HTTP headers, such as `Access-Control-Allow-Origin: https://myapp.com`, to grant permission.
44
+
45
+
39
46
Dependency Injection
40
47
--------------------
41
48
Dependency Injection (DI) is a design pattern that dictates how to separate the creation of objects from their dependencies. This means a class is not responsible for creating or initializing its dependencies; instead, these dependencies are provided by external code (which could be a [DI container |#Dependency Injection Container]). The advantage lies in increased code flexibility, better understandability, and easier application testing, as dependencies are easily replaceable and isolated from other code parts. More in the chapter [What is Dependency Injection? |dependency-injection:introduction]
0 commit comments