MCPcopy Index your code
hub / github.com/scality/cloudserver / getRemoteIPFromRequest

Function getRemoteIPFromRequest

lib/utilities/serverAccessLogger.js:182–208  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

180}
181
182function getRemoteIPFromRequest(request) {
183 let remoteIP = null;
184 if (request.headers) {
185 // Check for forwarded IP headers (proxy/load balancer scenarios)
186 const headerRemoteIP = request.headers['x-forwarded-for'] ||
187 request.headers['x-real-ip'] ||
188 request.headers['x-client-ip'] ||
189 request.headers['cf-connecting-ip']; // Cloudflare
190
191 // x-forwarded-for can contain multiple IPs, take the first one
192 if (headerRemoteIP) {
193 remoteIP = headerRemoteIP.includes(',') ? headerRemoteIP.split(',')[0].trim() : headerRemoteIP;
194 }
195 }
196
197 // Fallback to connection remote address if no forwarded headers
198 if (!remoteIP) {
199 const connIP = (request.connection && request.connection.remoteAddress) ||
200 (request.socket && request.socket.remoteAddress) ||
201 (request.ip);
202 if (connIP) {
203 remoteIP = connIP;
204 }
205 }
206
207 return remoteIP;
208}
209
210// eslint-disable-next-line max-len
211// https://github.com/awslabs/glue-extensions-for-iceberg/blob/52bdb2908216a85859fd76a45981d0326d016a2f/spark/src/main/scala/software/amazon/glue/s3a/audit/S3LogVerbs.java

Callers 2

buildLogEntryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected