Added mising check for existence of master request

Since <code>RequestStack::getMasterRequest()</code> also can return null, we need to make sure that <code>$request</code> is not null before performing any actions on it.