Skip to main content

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

X-Forwarded-Host

The original host or domain requested by the client.

X-Forwarded-Preferred-Username

The user name provided by IdP.

X-Forwarded-User

The user identifier provided by IdP.

X-Forwarded-Email

The user email provided by IdP.

X-Real-Ip

The IP address of the client that made the original request.

X-Request-Id

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

Python
from flask import Flask, request

app = Flask(__name__)

@app.route("/")
def index():
user = request.headers.get("X-Forwarded-User")
return f"Hello, {user}!"

FastAPI

Python
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.