Skip to content

Commit

Permalink
Make remote address available via requestContext.http.sourceIp
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 29, 2021
1 parent ff8b252 commit 45ae64d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ AWS Lambda Webservices change log

## ?.?.? / ????-??-??

* Made remote address available in HTTP headers, populated via events'
requestContext.http.sourceIp member
(@thekid)

## 0.4.1 / 2021-08-29

* Added various tests, increasing test coverage to 100%. See #3 - @thekid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function uri() {

/** @return iterable */
public function headers() {
yield 'remote-addr' => $this->event['requestContext']['http']['sourceIp'] ?? '127.0.0.1';
yield from $this->event['headers'] ?? [];
if (!empty($this->event['cookies'])) {
yield 'cookie' => implode('; ', $this->event['cookies']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function fixture($method= 'GET', $query= '', $headers= [], $body= null)
'method' => $method,
'path' => '/default/test',
'protocol' => 'HTTP/1.1',
'sourceIp' => '127.0.0.1',
'sourceIp' => '192.168.178.1',
'userAgent' => 'XP/Test'
],
'requestId' => 'JKJaXmPLvHcESHA=',
Expand Down Expand Up @@ -78,9 +78,9 @@ public function uri_including_query() {
}

#[Test, Values([[[]], [['accept' => '*/*', 'user-agent' => 'test']]])]
public function headers_include_cookies($headers) {
public function headers_include_cookies_and_remote_addr($headers) {
Assert::equals(
['cookie' => self::COOKIE] + $headers,
['remote-addr' => '192.168.178.1', 'cookie' => self::COOKIE] + $headers,
iterator_to_array($this->fixture('GET', '', $headers)->headers())
);
}
Expand Down

0 comments on commit 45ae64d

Please sign in to comment.