Request Headers
Headers
dataclass
A dataclass representing the headers of an HTTP request. This is primarily used for extracting authentication tokens and API keys from the request headers and cookies.
This class provides a convenient way to access authentication tokens and API keys, regardless of whether they are provided in the standard headers or in cookies. It provides properties to check the presence of these tokens and keys.
This class is designed to be immutable and uses slots for memory efficiency.
Source code in src/alpha/utils/request_headers.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
Methods:
from_headers
classmethod
from_headers(headers, auth_token_cookie_name='auth_token', refresh_token_cookie_name='refresh_token', api_key_cookie_name='api_key')
Create a Headers instance from a mapping of headers.
For the auth token, the method first checks the "Authorization" header.
If present, it extracts the token and its type (e.g., "Bearer"). If it
is not present, it looks for a cookie with the name specified by
auth_token_cookie_name. The same logic applies to the refresh token
and API key, checking the "X-Refresh-Token" and "X-API-Key" headers. If
they are not present, it looks for cookies with the names specified by
refresh_token_cookie_name and api_key_cookie_name.
| Parameters: |
|
|---|
| Returns: |
|
|---|