Access HTTP headers passed to Databricks apps
Databricks Apps passes specific X-Forwarded-*
HTTP headers from the reverse proxy to your app. Use these headers to access information about the original request, such as the client IP address or protocol.
Databricks Apps includes the following X-Forwarded-*
headers in requests that are forwarded from the reverse proxy to your app:
Header | Description |
---|---|
| The original host or domain requested by the client. |
| The user name provided by IdP. |
| The user identifier provided by IdP. |
| The user email provided by IdP. |
| The IP address of the client that made the original request. |
| The UUID of the request. |
Access headers in code
You can access forwarded headers in your app code using the request object provided by your web framework. The example below shows how to retrieve the X-Forwarded-User
header using popular Python frameworks:
Flask
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def index():
user = request.headers.get("X-Forwarded-User")
return f"Hello, {user}!"
FastAPI
from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/")
async def index(request: Request):
user = request.headers.get("X-Forwarded-User")
return {"message": f"Hello, {user}!"}
These headers are only available when the app runs inside Databricks Apps. When testing locally, you must simulate or manually include them.