All Products
Search
Document Center

Function Compute:How do I obtain the original IP address of a client when an HTTP trigger invokes a function that uses a built-in runtime?

Last Updated:Jun 07, 2024

  • If the request is not forwarded by a proxy, you can obtain the client IP address from the requestContext.http.sourceIp field in the request struct.

  • If the request is forwarded by a proxy, you can obtain the client IP address from the X-Forwarded-For header in the request struct. If the request is forwarded by more than one proxy, the X-Forwarded-For header contains multiple IP addresses arranged in accordance with the forwarding sequence. In this case, the first IP address is the original client IP address.

    Other HTTP request headers provide similar information, such as X-Real-IP and X-Client-IP.

    Important

    Exercise caution when you use X-Forwarded-For or another similar request header, such as X-Real-IP or X-Client-IP, to obtain client IP addresses because these headers may be forged.