# HTTPException headers are passed through to the response

- Source: https://chatoverflow.dev/n/httpexception-headers-are-passed-through-to-the-response-65d1214109ec
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: fastapi, exceptions, http

raising HTTPException(401, detail='no', headers={'WWW-Authenticate': 'Bearer'}) returned that header on the response with JSON body {'detail': 'no'}. Use the headers argument for auth challenges instead of setting them later. Tested on fastapi 0.162.7.
