Skip to content

Commit

Permalink
Merge pull request #155 from AlejandroBBL/master
Browse files Browse the repository at this point in the history
Added extra headers to Cloudflare Driver
  • Loading branch information
stevebauman authored Jan 10, 2024
2 parents d406651 + d78f5c1 commit 14a3a99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Drivers/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ protected function process(Request $request): Fluent|false
'cityName' => $request->getHeader('cf-ipcity'),
'longitude' => $request->getHeader('cf-iplongitude'),
'latitude' => $request->getHeader('cf-iplatitude'),
'region' => $request->getHeader('cf-region'),
'regionCode' => $request->getHeader('cf-region-code'),
'postalCode' => $request->getHeader('cf-postal-code'),
'timezone' => $request->getHeader('cf-timezone'),
]);
}

Expand All @@ -41,6 +45,10 @@ protected function hydrate(Position $position, Fluent $location): Position
$position->cityName = $location->cityName;
$position->longitude = $location->longitude;
$position->latitude = $location->latitude;
$position->regionName = $location->region;
$position->regionCode = $location->regionCode;
$position->postalCode = $location->postalCode;
$position->timezone = $location->timezone;

return $position;
}
Expand Down
12 changes: 8 additions & 4 deletions tests/CloudflareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
'CF-IPCity' => 'Boxford',
'CF-IPLatitude' => '51.75',
'CF-IPLongitude' => '-1.25',
'CF-Region' => 'Plymouth',
'CF-Region-Code' => 'PLY',
'CF-Postal-Code' => 'PL5',
'CF-Timezone' => 'Europe/London',
]);

$position = Location::get('2.125.160.216');
Expand All @@ -28,17 +32,17 @@
'ip' => '2.125.160.216',
'countryName' => null,
'countryCode' => 'GB',
'regionCode' => null,
'regionName' => null,
'regionCode' => 'PLY',
'regionName' => 'Plymouth',
'cityName' => 'Boxford',
'zipCode' => null,
'isoCode' => 'GB',
'postalCode' => null,
'postalCode' => 'PL5',
'latitude' => '51.75',
'longitude' => '-1.25',
'metroCode' => null,
'areaCode' => null,
'timezone' => null,
'timezone' => 'Europe/London',
'driver' => Cloudflare::class,
]);
});
Expand Down

0 comments on commit 14a3a99

Please sign in to comment.