Skip to content

Commit e13f765

Browse files
committed
Fix getting http headers
1 parent 422418a commit e13f765

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

lib/ApiClient/Http/Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ private function getLastElementOfLocationHeader(): ?string
7878

7979
private function getLocationHeaderContent(): ?string
8080
{
81-
foreach($this->getHeaders() as $header) {
82-
if (str_starts_with(strtolower((string) $header), 'location:')) {
83-
return trim(preg_replace('/^.+?:/', '', (string) $header));
81+
foreach($this->getHeaders() as $key => $content) {
82+
if (strtolower($key) === 'location') {
83+
return trim($content[0]);
8484
}
8585
}
8686

test/ApiClient/Http/ResponseTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public function testGettingGeneratedPid()
6666
$response = new Response(
6767
204,
6868
'',
69-
[ 'Some-Header: something',
70-
'Location: https://api.ticketpark.ch/some-entity/some-uuid'
69+
[
70+
'Some-Header' => ['something'],
71+
'Location' => ['https://api.ticketpark.ch/some-entity/some-uuid']
7172
]
7273
);
7374

@@ -80,7 +81,7 @@ public function testGettingGeneratedPidReturnsNullIfInexistent()
8081
204,
8182
'',
8283
[
83-
'Some-Header: something'
84+
'Some-Header' => ['something']
8485
]
8586
);
8687

@@ -93,8 +94,8 @@ public function testGettingGeneratedPidReturnsNullIfListLinkAvailable()
9394
204,
9495
'',
9596
[
96-
'Some-Header: something',
97-
'Location: https://api.ticketpark.ch/some-entity/filters[batchId]=some-uuid&orderBy[batchOrder]=asc'
97+
'Some-Header' => ['something'],
98+
'Location' => ['https://api.ticketpark.ch/some-entity/filters[batchId]=some-uuid&orderBy[batchOrder]=asc']
9899
]
99100
);
100101

@@ -106,8 +107,9 @@ public function testGettingGeneratedListLink()
106107
$response = new Response(
107108
204,
108109
'',
109-
[ 'Some-Header: something',
110-
'Location: https://api.ticketpark.ch/some-entity/filters[batchId]=some-uuid&orderBy[batchOrder]=asc'
110+
[
111+
'Some-Header' => ['something'],
112+
'Location' => ['https://api.ticketpark.ch/some-entity/filters[batchId]=some-uuid&orderBy[batchOrder]=asc']
111113
]
112114
);
113115

@@ -120,7 +122,7 @@ public function testGettingGeneratedListLinkReturnsNullIfInexistent()
120122
204,
121123
'',
122124
[
123-
'Some-Header: something',
125+
'Some-Header' => ['something']
124126
]
125127
);
126128

@@ -133,8 +135,8 @@ public function testGettingGeneratedListLinkReturnsNullIfPidAvailable()
133135
204,
134136
'',
135137
[
136-
'Some-Header: something',
137-
'Location: https://api.ticketpark.ch/some-entity/some-uuid'
138+
'Some-Header' => ['something'],
139+
'Location' => ['https://api.ticketpark.ch/some-entity/some-uuid']
138140
]
139141
);
140142

0 commit comments

Comments
 (0)