From 17c872b07964a7c233c2f25390f323070072b712 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 3 Oct 2018 06:10:26 -0400 Subject: [PATCH] Set a default user-agent header in WireHttp to resolve issues where accessed hostname seems to require it (noticed this on a couple hosts running Varnish, which seem to throw a 400/403 if no user-agent header present) --- wire/core/WireHttp.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wire/core/WireHttp.php b/wire/core/WireHttp.php index 4d3a21cb..db8a76d9 100644 --- a/wire/core/WireHttp.php +++ b/wire/core/WireHttp.php @@ -467,6 +467,13 @@ class WireHttp extends Wire { if(!empty($data)) $this->setData($data); + if(!isset($this->headers['user-agent'])) { + // some web servers deliver a 400 error if no user-agent set in request header, so make sure one is set + $this->setHeader('user-agent', + 'ProcessWire/' . ProcessWire::versionMajor . '.' . ProcessWire::versionMinor . ' (' . $this->className() . ')' + ); + } + if(!in_array(strtoupper($method), $this->allowHttpMethods)) $method = 'POST'; if(!$this->hasFopen || strpos($url, 'https://') === 0 && !extension_loaded('openssl')) {