Skip to content

Commit b92ea55

Browse files
authored
merge headers in OperatorTrait::sendRequest (#427)
* merge headers in `OperatorTrait::sendRequest` * remove bobcat integration tests
1 parent 94bac6d commit b92ea55

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

.github/workflows/integration_tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ jobs:
2828
- name: "caracal"
2929
openstack_version: "stable/2024.1"
3030
ubuntu_version: "22.04"
31-
- name: "bobcat"
32-
openstack_version: "stable/2023.2"
33-
ubuntu_version: "22.04"
3431
- name: "antelope"
3532
openstack_version: "unmaintained/2023.1"
3633
ubuntu_version: "22.04"

src/Common/Api/OperatorTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ protected function sendRequest(Operation $operation, array $userValues = [], boo
101101

102102
$uri = Utils::uri_template($operation->getPath(), $userValues);
103103

104-
if (array_key_exists('requestOptions', $userValues)) {
104+
if (isset($userValues['requestOptions'])) {
105105
$options += $userValues['requestOptions'];
106+
107+
// headers are always created in options, merge them
108+
if (isset($userValues['requestOptions']['headers'])) {
109+
$options['headers'] = array_merge($options['headers'], $userValues['requestOptions']['headers']);
110+
}
106111
}
107112

108113
$options['openstack.skip_auth'] = $operation->getSkipAuth();

tests/unit/Common/Api/OperatorTraitTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@ public function test_guzzle_options_are_forwarded()
111111
'requestOptions' => ['stream' => true],
112112
]);
113113
}
114+
115+
public function test_it_sends_custom_headers_in_request_options()
116+
{
117+
$this->client
118+
->requestAsync('GET', 'test',
119+
[
120+
'headers' => [
121+
'Access-Control-Allow-Origin' => '*',
122+
'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
123+
],
124+
'openstack.skip_auth' => false,
125+
])
126+
->shouldBeCalled()
127+
->willReturn(new Promise());
128+
129+
$this->operator->executeAsync($this->def, [
130+
'requestOptions' => [
131+
'headers' => [
132+
'Access-Control-Allow-Origin' => '*',
133+
'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
134+
],
135+
],
136+
]);
137+
}
114138
}
115139

116140

0 commit comments

Comments
 (0)