Skip to content

Commit

Permalink
feat(ip): Detect Fly-Client-IP header when available (#751)
Browse files Browse the repository at this point in the history
Closes #558

This detects IP via the `Fly-Client-IP` header if it is available. This follows the same pattern of other providers we support.
  • Loading branch information
blaine-arcjet authored May 13, 2024
1 parent 0ff6abc commit 73359f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,13 @@ function findIP(request: RequestLike, headers: Headers): string {
return trueClientIP;
}

// Fly.io
// Fly-Client-IP: https://fly.io/docs/networking/request-headers/#fly-client-ip
const flyClientIP = headers.get("fly-client-ip");
if (isGlobalIP(flyClientIP)) {
return flyClientIP;
}

// Default nginx proxy/fcgi; alternative to x-forwarded-for, used by some proxies
// X-Real-IP
const xRealIP = headers.get("x-real-ip");
Expand Down
1 change: 1 addition & 0 deletions ip/test/ipv4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe("find public IPv4", () => {
headerSuite("CF-Connecting-IP");
headerSuite("DO-Connecting-IP");
headerSuite("Fastly-Client-IP");
headerSuite("Fly-Client-IP");
headerSuite("True-Client-IP");
headerSuite("X-Real-IP");
headerSuite("X-Cluster-Client-IP");
Expand Down
1 change: 1 addition & 0 deletions ip/test/ipv6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ describe("find public IPv4", () => {
headerSuite("CF-Connecting-IP");
headerSuite("DO-Connecting-IP");
headerSuite("Fastly-Client-IP");
headerSuite("Fly-Client-IP");
headerSuite("True-Client-IP");
headerSuite("X-Real-IP");
headerSuite("X-Cluster-Client-IP");
Expand Down

0 comments on commit 73359f6

Please sign in to comment.