comparison vendor/guzzlehttp/guzzle/src/Client.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
288 * 288 *
289 * @return RequestInterface 289 * @return RequestInterface
290 */ 290 */
291 private function applyOptions(RequestInterface $request, array &$options) 291 private function applyOptions(RequestInterface $request, array &$options)
292 { 292 {
293 $modify = []; 293 $modify = [
294 'set_headers' => [],
295 ];
296
297 if (isset($options['headers'])) {
298 $modify['set_headers'] = $options['headers'];
299 unset($options['headers']);
300 }
294 301
295 if (isset($options['form_params'])) { 302 if (isset($options['form_params'])) {
296 if (isset($options['multipart'])) { 303 if (isset($options['multipart'])) {
297 throw new \InvalidArgumentException('You cannot use ' 304 throw new \InvalidArgumentException('You cannot use '
298 . 'form_params and multipart at the same time. Use the ' 305 . 'form_params and multipart at the same time. Use the '
300 . 'x-www-form-urlencoded requests, and the multipart ' 307 . 'x-www-form-urlencoded requests, and the multipart '
301 . 'option to send multipart/form-data requests.'); 308 . 'option to send multipart/form-data requests.');
302 } 309 }
303 $options['body'] = http_build_query($options['form_params'], '', '&'); 310 $options['body'] = http_build_query($options['form_params'], '', '&');
304 unset($options['form_params']); 311 unset($options['form_params']);
312 // Ensure that we don't have the header in different case and set the new value.
313 $options['_conditional'] = Psr7\_caseless_remove(['Content-Type'], $options['_conditional']);
305 $options['_conditional']['Content-Type'] = 'application/x-www-form-urlencoded'; 314 $options['_conditional']['Content-Type'] = 'application/x-www-form-urlencoded';
306 } 315 }
307 316
308 if (isset($options['multipart'])) { 317 if (isset($options['multipart'])) {
309 $options['body'] = new Psr7\MultipartStream($options['multipart']); 318 $options['body'] = new Psr7\MultipartStream($options['multipart']);
311 } 320 }
312 321
313 if (isset($options['json'])) { 322 if (isset($options['json'])) {
314 $options['body'] = \GuzzleHttp\json_encode($options['json']); 323 $options['body'] = \GuzzleHttp\json_encode($options['json']);
315 unset($options['json']); 324 unset($options['json']);
325 // Ensure that we don't have the header in different case and set the new value.
326 $options['_conditional'] = Psr7\_caseless_remove(['Content-Type'], $options['_conditional']);
316 $options['_conditional']['Content-Type'] = 'application/json'; 327 $options['_conditional']['Content-Type'] = 'application/json';
317 } 328 }
318 329
319 if (!empty($options['decode_content']) 330 if (!empty($options['decode_content'])
320 && $options['decode_content'] !== true 331 && $options['decode_content'] !== true
321 ) { 332 ) {
333 // Ensure that we don't have the header in different case and set the new value.
334 $options['_conditional'] = Psr7\_caseless_remove(['Accept-Encoding'], $options['_conditional']);
322 $modify['set_headers']['Accept-Encoding'] = $options['decode_content']; 335 $modify['set_headers']['Accept-Encoding'] = $options['decode_content'];
323 }
324
325 if (isset($options['headers'])) {
326 if (isset($modify['set_headers'])) {
327 $modify['set_headers'] = $options['headers'] + $modify['set_headers'];
328 } else {
329 $modify['set_headers'] = $options['headers'];
330 }
331 unset($options['headers']);
332 } 336 }
333 337
334 if (isset($options['body'])) { 338 if (isset($options['body'])) {
335 if (is_array($options['body'])) { 339 if (is_array($options['body'])) {
336 $this->invalidBody(); 340 $this->invalidBody();
342 if (!empty($options['auth']) && is_array($options['auth'])) { 346 if (!empty($options['auth']) && is_array($options['auth'])) {
343 $value = $options['auth']; 347 $value = $options['auth'];
344 $type = isset($value[2]) ? strtolower($value[2]) : 'basic'; 348 $type = isset($value[2]) ? strtolower($value[2]) : 'basic';
345 switch ($type) { 349 switch ($type) {
346 case 'basic': 350 case 'basic':
351 // Ensure that we don't have the header in different case and set the new value.
352 $modify['set_headers'] = Psr7\_caseless_remove(['Authorization'], $modify['set_headers']);
347 $modify['set_headers']['Authorization'] = 'Basic ' 353 $modify['set_headers']['Authorization'] = 'Basic '
348 . base64_encode("$value[0]:$value[1]"); 354 . base64_encode("$value[0]:$value[1]");
349 break; 355 break;
350 case 'digest': 356 case 'digest':
351 // @todo: Do not rely on curl 357 // @todo: Do not rely on curl
380 } 386 }
381 387
382 $request = Psr7\modify_request($request, $modify); 388 $request = Psr7\modify_request($request, $modify);
383 if ($request->getBody() instanceof Psr7\MultipartStream) { 389 if ($request->getBody() instanceof Psr7\MultipartStream) {
384 // Use a multipart/form-data POST if a Content-Type is not set. 390 // Use a multipart/form-data POST if a Content-Type is not set.
391 // Ensure that we don't have the header in different case and set the new value.
392 $options['_conditional'] = Psr7\_caseless_remove(['Content-Type'], $options['_conditional']);
385 $options['_conditional']['Content-Type'] = 'multipart/form-data; boundary=' 393 $options['_conditional']['Content-Type'] = 'multipart/form-data; boundary='
386 . $request->getBody()->getBoundary(); 394 . $request->getBody()->getBoundary();
387 } 395 }
388 396
389 // Merge in conditional headers if they are not present. 397 // Merge in conditional headers if they are not present.