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
The response from the request is returned as a [Response](https://github.com/alexsandrov16/http/blob/main/docs/response.md) object. You can access the content, status code, and headers of the response.
47
+
The response from the request is returned as a [Response](https://github.com/al3x5dev/http/blob/main/docs/response.md) object. You can access the content, status code, and headers of the response.
This static method adds a cookie before sending it to the browser with the specified parameters. Returns true if the cookie was set correctly, otherwise returns false.
6
6
7
7
**Parameters:**
8
8
-`$name` (string): The name of the cookie.
9
9
-`$value` (mixed): The value of the cookie.
10
10
-`$expires` (int): The expiration time of the cookie in seconds from the current time. Default is 0 (does not expire).
11
11
-`$path` (string): Path where the cookie will be available. Default is '/'.
12
-
-`$domain` (string|null): Domain to which the cookie is associated. Default is null.
13
-
-`$secure` (bool): Indicates if the cookie should only be sent through secure connections. Default is false.
14
-
-`$httponly` (bool): Indicates whether the cookie should only be accessible via HTTP. Default is false.
12
+
-`$domain` (string): Domain to which the cookie is associated. Default is empty string.
13
+
-`$secure` (bool): Indicates if the cookie should only be sent through secure connections (HTTPS). Default is false.
14
+
-`$httponly` (bool): Indicates whether the cookie should only be accessible via HTTP (not JavaScript). Default is true.
15
+
-`$sameSite` (string): SameSite attribute - must be 'Strict', 'Lax', or 'None'. Default is 'Lax'.
Copy file name to clipboardExpand all lines: docs/headers.md
+52-12Lines changed: 52 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,27 @@
1
1
# Headers
2
-
The Trait `Headers` provides functionality related to the headers of an HTTP message. It is used only by the [Mk4U\Http\Request.php](https://github.com/alexsandrov16/http/blob/main/docs/request.md) and [Mk4U\Http\Response.php](https://github.com/alexsandrov16/http/blob/main/docs/response.md) classes.
2
+
The Trait `Headers` provides functionality related to the headers of an HTTP message. It is used only by the [Mk4U\Http\Request.php](https://github.com/al3x5dev/http/blob/main/docs/request.md) and [Mk4U\Http\Response.php](https://github.com/al3x5dev/http/blob/main/docs/response.md) classes.
Copy file name to clipboardExpand all lines: docs/request.md
+48-5Lines changed: 48 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ The `Request` class allows you to interact with the data coming into your applic
6
6
There are two ways to create a new Request object, you can create a request based on PHP's superglobal variables, or simply simulate a request:
7
7
8
8
### Simulating a request
9
-
When you simulate a request you must pass as parameters the http method, the uri or a [Uri object](https://github.com/alexsandrov16/http/blob/main/docs/uri.md), the headers (optional), the request body (optional) and the protocol version (optional).
9
+
When you simulate a request you must pass as parameters the http method, the uri or a [Uri object](https://github.com/al3x5dev/http/blob/main/docs/uri.md), the headers (optional), the request body (optional) and the protocol version (optional).
This method sets the [Uri object](https://github.com/alexsandrov16/http/blob/main/docs/uri.md) for the current request and optionally preserves the host in the request headers. Returns a copy of the Request object with the updated [Uri](https://github.com/alexsandrov16/http/blob/main/docs/uri.md) object and, optionally, the preserved host in the headers.
88
+
This method sets the [Uri object](https://github.com/al3x5dev/http/blob/main/docs/uri.md) for the current request and optionally preserves the host in the request headers. Returns a copy of the Request object with the updated [Uri](https://github.com/al3x5dev/http/blob/main/docs/uri.md) object and, optionally, the preserved host in the headers.
89
89
90
90
**Parameters:**
91
-
-`$uri` (Uri): the [Uri object](https://github.com/alexsandrov16/http/blob/main/docs/uri.md) to set for the request.
91
+
-`$uri` (Uri): the [Uri object](https://github.com/al3x5dev/http/blob/main/docs/uri.md) to set for the request.
92
92
-`$preserv_host` (bool): Indicates whether to preserve the host in the request
93
93
```php
94
94
$request->setUri($uri);
@@ -97,7 +97,7 @@ $request->setUri($uri,true);
97
97
```
98
98
99
99
### Method `Request::getUri()`.
100
-
This method returns the [Uri object](https://github.com/alexsandrov16/http/blob/main/docs/uri.md) associated with the current request.
100
+
This method returns the [Uri object](https://github.com/al3x5dev/http/blob/main/docs/uri.md) associated with the current request.
101
101
```php
102
102
$request->getUri();
103
103
// return object(Mk4U\Http\Uri)
@@ -174,7 +174,7 @@ $request->rawData();
174
174
```
175
175
176
176
### Method `Request::files()`.
177
-
This method returns an array containing the files uploaded to the server in the current request stored in the [UploadedFile](https://github.com/alexsandrov16/http/blob/main/docs/uploadedfile.md) or an empty array if there are no files.
177
+
This method returns an array containing the files uploaded to the server in the current request stored in the [UploadedFile](https://github.com/al3x5dev/http/blob/main/docs/uploadedfile.md) or an empty array if there are no files.
178
178
```php
179
179
$request->files();
180
180
/* return [
@@ -187,3 +187,46 @@ $request->files();
187
187
}
188
188
]*/
189
189
```
190
+
191
+
### Method `Request::getMethod()`.
192
+
This method returns the HTTP method used in the request as an uppercase string.
193
+
```php
194
+
$request->getMethod();
195
+
// return "GET", "POST", "PUT", etc.
196
+
```
197
+
198
+
### Method `Request::getUri()`.
199
+
This method returns the [Uri object](https://github.com/al3x5dev/http/blob/main/docs/uri.md) associated with the current request.
This method sets the [Uri object](https://github.com/al3x5dev/http/blob/main/docs/uri.md) for the current request. Optionally preserves the host header.
207
+
208
+
**Parameters:**
209
+
-`$uri` (Uri): The Uri object to set.
210
+
-`$preserveHost` (bool): If true, preserves the existing Host header. Default is false.
211
+
212
+
```php
213
+
$uri = new Uri('https://example.com/path');
214
+
$request->setUri($uri);
215
+
216
+
// With host preservation
217
+
$request->setUri($uri, true);
218
+
```
219
+
220
+
### Method `Request::getTarget()`.
221
+
This method returns the target path of the request (the URI path).
222
+
```php
223
+
$request->getTarget();
224
+
// return "/path/to/resource" or "/" if empty
225
+
```
226
+
227
+
### Method `Request::isFormData()`.
228
+
This method determines if the request contains form data (application/x-www-form-urlencoded or multipart/form-data with POST method).
The `Response::download()`, `Response::file()`, and `Response::streamDownload()` methods automatically detect the MIME type based on the file extension:
0 commit comments