Commit c4e97eb
committed
feature symfony#52946 [HttpClient] Add HttpOptions->addHeader as a shortcut to add an header in an existing options object (Dean151)
This PR was squashed before being merged into the 7.1 branch.
Discussion
----------
[HttpClient] Add HttpOptions->addHeader as a shortcut to add an header in an existing options object
| Q | A
| ------------- | ---
| Branch? | 7.1
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues |
| License | MIT
Currently, the HttpOptions object only provide a ->setHeaders option that override every existing headers. When we are provided an HttpOptions to customize a request, adding a request header requires to get the whole headers array, update it, and then set it back in the HttpOptions object. This DX improvement brings an addHeader option, allowing to add an header to the set without having to manage the existing ones.
When the header option is not yet provided, the ??= operator makes sure the headers is initialized with an empty array (PHP >= 7.4) When a header is already provided, it is overwritten.
Commits
-------
266e50f [HttpClient] Add HttpOptions->addHeader as a shortcut to add an header in an existing options objectFile tree
2 files changed
+22
-0
lines changed- src/Symfony/Component/HttpClient
- Tests
2 files changed
+22
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
66 | 77 | | |
67 | 78 | | |
68 | 79 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
42 | 53 | | |
0 commit comments