Serverless Functions HTTP headers reference
Scaleway Serverless Functions automatically inject several HTTP headers into every incoming request. These headers provide metadata about the request, the client, and the routing path through the Scaleway infrastructure.
You can use these headers within your function logic for logging, security, and request tracing.
Injected headers reference
The following headers are available in the request object of your function.
| Header | Description |
|---|---|
X-Forwarded-For | A standard header used to identify the originating IP address of a client connecting through an HTTP proxy or load balancer. |
X-Forwarded-Proto | A header indicating the protocol (HTTP or HTTPS) used by the client to connect to the container. |
X-Request-ID | A unique string assigned to each incoming request to facilitate tracing and debugging. |
Alongside these headers, the following headers are set for internal purposes. Users should be careful when using them, as their presence/contents is not guaranteed:
| Header | Description |
|---|---|
K-Proxy-Request | Internal. Used by the underlying architecture. |
X-Envoy-External-Address | Deprecated. Prefer using X-Real-IP. |
Detailed use cases
Request tracing and debugging
The X-Request-ID header is essential for distributed tracing. Each request receives a unique identifier that persists throughout the lifecycle of the request within the Scaleway ecosystem.
- Log correlation: Log the
X-Request-IDat the start of your function. If a request fails, you can use this ID to search your Serverless Functions logs for entries related to that specific execution. The request ID does not appear in user logs by default. To include it, propagate the header value yourself. - Cross-service tracking: If your function calls another service, pass the
X-Request-IDalong to maintain a consistent trace across your architecture.
Client IP identification
Use the X-Real-IP header to identify the IP address of the client. It contains the list of IP addresses the request has passed through, with the original client IP as the first entry. You can use X-Forwarded-For if the connection has proxies, but note that it can be tampered by the client.
- Security and filtering: Use
X-Real-IPto implement IP-based rate limiting or to allow/deny requests from specific geographic regions within your application logic. - Analytics: Use
X-Real-IPto determine the general location of your users without relying on internal routing IPs.
Protocol enforcement
The X-Forwarded-Proto header allows your function to determine if the user is connecting over a secure connection.
- HTTPS redirection: If your function logic requires a secure connection, you can check if
X-Forwarded-Protoishttpand respond with a redirect to the HTTPS version of your endpoint.