Skip to content

Commit 1c74be0

Browse files
committed
merge headers in OperatorTrait::sendRequest
1 parent 94bac6d commit 1c74be0

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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)