Skip to content

Commit 74de08a

Browse files
authored
Merge pull request #55 from understand/feature/add-host-origin-fields
Add host and origin fields
2 parents c00d1d2 + 810a641 commit 74de08a

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/Understand/UnderstandLaravel5/ExceptionLogger.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ protected function getMetaFields()
139139
'client_ip' => 'UnderstandFieldProvider::getClientIp',
140140
'server_ip' => 'UnderstandFieldProvider::getServerIp',
141141
'user_agent' => 'UnderstandFieldProvider::getClientUserAgent',
142+
'host' => 'UnderstandFieldProvider::getHost',
143+
'origin' => 'UnderstandFieldProvider::getOrigin',
142144
'laravel_version' => 'UnderstandFieldProvider::getLaravelVersion',
143145
'sql_queries' => 'UnderstandFieldProvider::getSqlQueries',
144146
'artisan_command' => 'UnderstandFieldProvider::getArtisanCommandName',

src/Understand/UnderstandLaravel5/FieldProvider.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class FieldProvider
3131
'getServerIp',
3232
'getClientIp',
3333
'getClientUserAgent',
34+
'getHost',
35+
'getOrigin',
3436
'getEnvironment',
3537
'getFromSession',
3638
'getProcessIdentifier',
@@ -548,6 +550,36 @@ protected function getClientUserAgent()
548550
return $this->request->server->get('HTTP_USER_AGENT');
549551
}
550552

553+
/**
554+
* Return client host
555+
*
556+
* @return string
557+
*/
558+
protected function getHost()
559+
{
560+
if ( ! $this->request)
561+
{
562+
return null;
563+
}
564+
565+
return $this->request->server->get('HTTP_HOST');
566+
}
567+
568+
/**
569+
* Return client origin
570+
*
571+
* @return string
572+
*/
573+
protected function getOrigin()
574+
{
575+
if ( ! $this->request)
576+
{
577+
return null;
578+
}
579+
580+
return $this->request->server->get('HTTP_ORIGIN');
581+
}
582+
551583
/**
552584
* Return current enviroment
553585
*

tests/FieldProviderTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ public function testGetServerIp()
147147
$this->assertEquals('127.0 0.1', $ip);
148148
}
149149

150+
public function testGetHost()
151+
{
152+
\Illuminate\Support\Facades\Route::get('/', function() {});
153+
154+
$this->call('GET', '/', [], [], [], []);
155+
156+
$host = $this->app['understand.fieldProvider']->getHost();
157+
158+
$this->assertEquals('localhost', $host);
159+
}
160+
161+
public function testGetOrigin()
162+
{
163+
\Illuminate\Support\Facades\Route::get('/', function() {});
164+
165+
$this->call('GET', '/', [], [], [], ['HTTP_ORIGIN' => 'remote.host']);
166+
167+
$origin = $this->app['understand.fieldProvider']->getOrigin();
168+
169+
$this->assertEquals('remote.host', $origin);
170+
}
171+
150172
public function testQueryString()
151173
{
152174
\Illuminate\Support\Facades\Route::get('/test', function() {});
@@ -223,7 +245,7 @@ public function testPostRequestParametersDisabled()
223245

224246
$this->assertTrue(empty($postData));
225247
}
226-
248+
227249
public function testGroupIdStaysTheSame()
228250
{
229251
$data = [

0 commit comments

Comments
 (0)