@@ -88,6 +88,9 @@ class Client
88
88
/** @var float Number of seconds to sleep before retrying after a server error */
89
89
public $ sleepTimeOnServerError = 10 ;
90
90
91
+ /** @var array Extra request headers */
92
+ public $ extraHeaders = [];
93
+
91
94
/**
92
95
* @var Conf
93
96
*/
@@ -118,6 +121,7 @@ class Client
118
121
* @param ?RequestFactoryInterface $requestFactory
119
122
* @param ?UriFactoryInterface $uriFactory
120
123
* @param ?string $baseUrl
124
+ * @param array $extraHeaders
121
125
*
122
126
* @throws \ErrorException
123
127
*/
@@ -128,7 +132,8 @@ public function __construct(
128
132
HttpClientInterface $ http = null ,
129
133
RequestFactoryInterface $ requestFactory = null ,
130
134
UriFactoryInterface $ uriFactory = null ,
131
- string $ baseUrl = null
135
+ string $ baseUrl = null ,
136
+ array $ extraHeaders = []
132
137
) {
133
138
$ this ->http = new PluginClient (
134
139
$ http ?: HttpClient::client (),
@@ -148,6 +153,8 @@ public function __construct(
148
153
$ this ->setRegion ($ region );
149
154
}
150
155
156
+ $ this ->extraHeaders = $ extraHeaders ;
157
+
151
158
$ this ->zone = $ zone ;
152
159
153
160
$ this ->bibs = new Bibs ($ this );
@@ -163,7 +170,16 @@ public function __construct(
163
170
$ this ->taskLists = new TaskLists ($ this );
164
171
165
172
if ($ zone == Zones::INSTITUTION ) {
166
- $ this ->nz = new self (null , $ region , Zones::NETWORK , $ this ->http , $ this ->requestFactory , $ this ->uriFactory , $ baseUrl );
173
+ $ this ->nz = new self (
174
+ null ,
175
+ $ region ,
176
+ Zones::NETWORK ,
177
+ $ this ->http ,
178
+ $ this ->requestFactory ,
179
+ $ this ->uriFactory ,
180
+ $ baseUrl ,
181
+ $ extraHeaders
182
+ );
167
183
} elseif ($ zone != Zones::NETWORK ) {
168
184
throw new AlmaClientException ('Invalid zone name. ' );
169
185
}
@@ -287,6 +303,9 @@ public function request(RequestInterface $request, $attempt = 1)
287
303
if (!$ this ->key ) {
288
304
throw new AlmaClientException ('No API key defined for ' . $ this ->zone );
289
305
}
306
+ foreach ($ this ->extraHeaders as $ key => $ val ) {
307
+ $ request = $ request ->withHeader ($ key , $ val );
308
+ }
290
309
291
310
try {
292
311
return $ this ->http ->sendRequest ($ request );
0 commit comments