Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
http_codes.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: http_codes.py
14# CREATION DATE: 11-10-2025
15# LAST Modified: 22:59:13 26-01-2026
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: File containing the list of http codes that can be sent and received by the server.
21# // AR
22# +==== END CatFeeder =================+
23"""
24
25import os
26from typing import Mapping, Dict, Any, Optional, Union, TypeAlias
27
28from fastapi.responses import (
29 Response, FileResponse, HTMLResponse, JSONResponse,
30 PlainTextResponse, RedirectResponse, StreamingResponse,
31 UJSONResponse, ORJSONResponse
32)
33
34from . import http_constants as CONST
35from ..core import FinalClass
36
37# Accept either a `DataTypes` enum member or a string key/MIME type
38ContentTypeLike: TypeAlias = Union[CONST.DataTypes, str]
39
40
41class HttpCodes(metaclass=FinalClass):
42 """HTTP status code response handler using FastAPI response types.
43
44 Provides methods for returning standardized HTTP responses with appropriate
45 status codes, content types, and headers. Supports JSON, plain text, HTML,
46 binary, file, and redirect responses.
47
48 HTTP Response Categories:
49 - 1xx: Informational
50 - 2xx: Successful
51 - 3xx: Redirection
52 - 4xx: Client error
53 - 5xx: Server error
54 """
55
56 def __init__(self) -> None:
57 self.authorised_statusesauthorised_statuses = CONST.AUTHORISED_STATUSES
58 self.data_types = CONST.DATA_TYPES
59
60 # """ General basic success message that speaks on channel 200 by default """
61
62 def _check_data_type(self, data_type: Optional[ContentTypeLike] = None) -> str:
63 """Validate and normalize provided content type to canonical MIME string.
64
65 Resolves content type from DataTypes enum member, known key string, or raw MIME type string to standardized MIME format.
66
67 Args:
68 data_type (ContentTypeLike, optional): Desired content type or alias.
69
70 Returns:
71 str: Canonical MIME type string (e.g., "application/json").
72
73 Raises:
74 TypeError: If the provided type cannot be resolved to a known or valid MIME type.
75 """
76 if data_type is None:
77 return "text/plain"
78
79 if isinstance(data_type, CONST.DataTypes):
80 return data_type.value
81
82 if isinstance(data_type, str):
83 resolved = CONST.DataTypes.from_key(data_type)
84 if resolved is not None:
85 return resolved.value
86
87 lowered = data_type.lower()
88 if lowered in self.data_types:
89 return self.data_types[lowered]
90 if data_type in self.data_types.values():
91 return data_type
92
93 raise TypeError(f"Invalid data type: {data_type}")
94
95 def _check_header(self, header: Optional[Mapping[str, str]] = None) -> Any:
96 """Validate and normalize HTTP headers.
97
98 Args:
99 header (Mapping[str, str], optional): _description_. Defaults to None.
100 Returns:
101 Any: Returns the correct known version of the sent headers.
102 Raises:
103 TypeError: If header is not a Mapping or Dict.
104 """
105 if header is None:
106 return {}
107 if not isinstance(header, (Dict, Mapping)):
108 raise TypeError(
109 f"Invalid header format, the format you provided is: {type(header)}"
110 )
111 return dict(header)
112
113 def _process_data_content(self, data: Any, data_type: str) -> Any:
114 """Process data content for HTTP response based on MIME type.
115
116 Handles binary passthrough, file-like objects, JSON, and streaming data.
117
118 Args:
119 data (Any): _description_: The data to be sent.
120 data_type (str): _description_: The type of the data to be sent.
121
122 Returns:
123 Any: Processed data in appropriate format for response type.
124 """
125 if data is None:
126 return ""
127 # Binary passthrough
128 if isinstance(data, (bytes, bytearray)):
129 return data
130 # File-like object
131 if hasattr(data, "read"):
132 return data
133 # JSON: let JSONResponse handle encoding
134 if data_type in CONST.JSON_MIME_TYPES:
135 return data
136 # Streaming: allow raw data
137 if data_type in CONST.STREAMING_MIME_TYPES:
138 return data
139 return str(data)
140
141 def _package_correctly(self, status: int = 200, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Union[Response, FileResponse, HTMLResponse, JSONResponse, PlainTextResponse, RedirectResponse, StreamingResponse, UJSONResponse, ORJSONResponse]:
142 """Route response content to appropriate FastAPI response class.
143
144 Determines correct response type based on content type and returns properly formatted response with status code, content, type, and headers.
145
146 Args:
147 status (int, optional): HTTP status code. Defaults to 200.
148 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
149 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
150 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
151
152 Raises:
153 TypeError: If content type is incompatible with content.
154
155 Returns:
156 Union[Response, FileResponse, HTMLResponse, JSONResponse, PlainTextResponse,
157 RedirectResponse, StreamingResponse, UJSONResponse, ORJSONResponse]: _description_
158 """
159 # Returning the content as a response if the payload data is bytes or a string that does not respresent a file.
160 if isinstance(content, bytes):
161 return Response(
162 content=content,
163 status_code=status,
164 headers=headers,
165 media_type=content_type
166 )
167
168 # Streaming / Binary (check BEFORE FILE because OCTET_STREAM is in both categories)
169 if content_type in CONST.STREAMING_MIME_TYPES:
170 # For actual iterables/generators, use StreamingResponse
171 return StreamingResponse(
172 content=content,
173 status_code=status,
174 headers=headers,
175 media_type=content_type
176 )
177
178 # FILE BASED
179 if content_type in CONST.FILE_MIME_TYPES:
180 if not isinstance(content, str):
181 raise TypeError(
182 "FileResponse requires the content to be a file path string."
183 )
184 # manual override in case the content is not a file path but it's raw content
185 if not os.path.isfile(content):
186 return Response(
187 content=content,
188 status_code=status,
189 headers=headers,
190 media_type=content_type
191 )
192 return FileResponse(
193 path=content,
194 status_code=status,
195 headers=headers,
196 media_type=content_type,
197 filename=os.path.basename(content)
198 )
199
200 # HTML / XML / JS
201 if content_type in CONST.HTML_MIME_TYPES:
202 return HTMLResponse(
203 content=content,
204 status_code=status,
205 headers=headers,
206 media_type=content_type
207 )
208
209 # JSON
210 if content_type in CONST.JSON_MIME_TYPES:
211 return JSONResponse(
212 content=content,
213 status_code=status,
214 headers=headers,
215 media_type=content_type
216 )
217
218 # Plain text
219 if content_type in CONST.PLAIN_TEXT_MIME_TYPES:
220 return PlainTextResponse(
221 content=content,
222 status_code=status,
223 headers=headers,
224 media_type=content_type
225 )
226
227 # Redirect
228 if content_type in CONST.REDIRECT_MIME_TYPES:
229 return RedirectResponse(
230 url=str(content),
231 status_code=status,
232 headers=headers
233 )
234
235 # UJSON
236 if content_type in CONST.UJSON_MIME_TYPES:
237 return UJSONResponse(
238 content=content,
239 status_code=status,
240 headers=headers,
241 media_type=content_type
242 )
243
244 # ORJSON
245 if content_type in CONST.ORJSON_MIME_TYPES:
246 return ORJSONResponse(
247 content=content,
248 status_code=status,
249 headers=headers,
250 media_type=content_type
251 )
252
253 # Default Response catch-all
254 return Response(
255 content=content,
256 status_code=status,
257 headers=headers,
258 media_type=content_type
259 )
260
261 def send_message_on_status(self, status: int = 200, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
262 """Send HTTP response with specified status code and content.
263
264 Args:
265 status (int, optional): HTTP status code. Defaults to 200.
266 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
267 content_type (ContentTypeLike, optional): MIME type as DataTypes, known key, or string. Defaults to DEFAULT_MESSAGE_TYPE.
268 headers (Mapping[str, str], optional): HTTP headers mapping. Defaults to None.
269
270 Raises:
271 ValueError: If status code is not authorized.
272
273 Returns:
274 Response: FastAPI response object.
275 """
276 # Validate status code
277 if isinstance(status, str) and status.isdigit():
278 status = int(status)
279
281 raise ValueError(f"Invalid HTTP status code: {status}")
282
283 # Validate content-type + headers
284 data_type = self._check_data_type(content_type)
285 data_header = self._check_header(headers)
286 data = self._process_data_content(content, data_type)
287
288 if isinstance(status, str) and status.isnumeric():
289 status = int(status)
290
291 if status not in self.authorised_statusesauthorised_statuses:
292 raise ValueError(
293 f"Invalid status code, the code you entered is: {status}"
294 )
295
296 # Route to correct Response class
297 return self._package_correctly(
298 status=status,
299 content=data,
300 content_type=data_type,
301 headers=data_header
302 )
303
304 # """ 1xx informational response"""
305
306 def send_continue(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
307 """Send 100 Continue HTTP response.
308
309 Indicates initial part of request received; client should continue or ignore if already finished.
310
311 Args:
312 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
313 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
314 headers (Mapping[str,str], optional): HTTP headers mapping. Defaults to None.
315
316 Returns:
317 Response: A FastAPI Response object with status 100.
318 """
319 return self.send_message_on_status(status=100, content=content, content_type=content_type, headers=headers)
320
321 def switching_protocols(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
322 """Send 101 Switching Protocols HTTP response.
323
324 Server switches protocols as requested by client, typically for WebSocket.
325
326 Args:
327 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
328 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
329 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
330
331 Returns:
332 Response: FastAPI Response object with status 101.
333 """
334 return self.send_message_on_status(status=101, content=content, content_type=content_type, headers=headers)
335
336 def processing(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
337 """Send 102 Processing HTTP response.
338
339 Server has received and is processing request; no response available yet. Commonly used in WebDAV.
340
341 Args:
342 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
343 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
344 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
345
346 Returns:
347 Response: FastAPI Response object with status 102.
348 """
349 return self.send_message_on_status(status=102, content=content, content_type=content_type, headers=headers)
350
351 def early_hints(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
352 """Send 103 Early Hints HTTP response.
353
354 Preload resources while server prepares final response. Improves page load.
355
356 Args:
357 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
358 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
359 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
360
361 Returns:
362 Response: FastAPI Response object with status 103.
363 """
364 return self.send_message_on_status(status=103, content=content, content_type=content_type, headers=headers)
365
366 def response_is_stale(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
367 """Send 110 Response Is Stale HTTP response.
368
369 Cached response is stale but still usable. Used in caching scenarios.
370
371 Args:
372 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
373 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
374 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
375
376 Returns:
377 Response: FastAPI Response object with status 110.
378 """
379 return self.send_message_on_status(status=110, content=content, content_type=content_type, headers=headers)
380
381 # """success: 200"""
382
383 def success(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
384 """Send 200 OK HTTP response.
385
386 Request succeeded. Meaning depends on HTTP method (GET, POST, etc.).
387
388 Args:
389 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
390 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
391 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
392
393 Returns:
394 Response: FastAPI Response object with status 200.
395 """
396 return self.send_message_on_status(status=200, content=content, content_type=content_type, headers=headers)
397
398 def created(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
399 """Send 201 Created HTTP response.
400
401 Request fulfilled; new resource created.
402
403 Args:
404 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
405 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
406 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
407
408 Returns:
409 Response: FastAPI Response object with status 201.
410 """
411 return self.send_message_on_status(status=201, content=content, content_type=content_type, headers=headers)
412
413 def accepted(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
414 """Send 202 Accepted HTTP response.
415
416 Request accepted for processing but not yet completed. Used for async ops.
417
418 Args:
419 content (Any, optional): Response content. Defaults to DEFAULT_MESSAGE_CONTENT.
420 content_type (ContentTypeLike, optional): MIME type or DataTypes member. Defaults to DEFAULT_MESSAGE_TYPE.
421 headers (Optional[Mapping[str, str]], optional): HTTP headers mapping. Defaults to None.
422
423 Returns:
424 Response: FastAPI Response object with status 202.
425 """
426 return self.send_message_on_status(status=202, content=content, content_type=content_type, headers=headers)
427
428 def non_authoritative_information(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
429 """Send 203 Non-Authoritative Information HTTP response.
430
431 Request succeeded
432 returned info from third-party source.
433
434 Args:
435 content_type: MIME type or DataTypes member.
436 Defaults to DEFAULT_MESSAGE_TYPE.
437 content(Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
438 content_type(ContentTypeLike, optional): Content type as `DataTypes` member, known key(e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
439 headers(Mapping[str, str], optional): Additional headers to include. Defaults to None.
440
441 Returns:
442 Response: A FastAPI Response object with status 203.
443 """
444 return self.send_message_on_status(status=203, content=content, content_type=content_type, headers=headers)
445
446 def no_content(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
447 """
448 Send a 204 No Content HTTP response.
449
450 This response indicates that the server successfully processed the request,
451 but is not returning any content. Typically used for DELETE operations.
452
453 Args:
454 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
455 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
456 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
457
458 Returns:
459 Response: A FastAPI Response object with status 204.
460 """
461 return self.send_message_on_status(status=204, content=content, content_type=content_type, headers=headers)
462
463 def reset_content(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
464 """
465 Send a 205 Reset Content HTTP response.
466
467 This response indicates that the server successfully processed the request,
468 and the user agent should reset the document view.
469
470 Args:
471 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
472 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
473 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
474
475 Returns:
476 Response: A FastAPI Response object with status 205.
477 """
478 return self.send_message_on_status(status=205, content=content, content_type=content_type, headers=headers)
479
480 def partial_content(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
481 """
482 Send a 206 Partial Content HTTP response.
483
484 This response indicates that the server is delivering only part of the
485 resource due to a range header sent by the client.
486
487 Args:
488 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
489 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
490 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
491
492 Returns:
493 Response: A FastAPI Response object with status 206.
494 """
495 return self.send_message_on_status(status=206, content=content, content_type=content_type, headers=headers)
496
497 def multi_status(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
498 """
499 Send a 207 Multi-Status HTTP response.
500
501 Used by WebDAV to convey status for multiple independent sub-requests
502 (e.g., batch file operations). The response body typically enumerates
503 individual resource states with their own status codes. Prefer this
504 when returning heterogeneous results for a single compound action.
505
506 Args:
507 content (Any, optional): Structured status description (often JSON/XML). Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
508 content_type (str, optional): Media type for the body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
509 headers (Mapping[str, str], optional): Extra response headers. Defaults to None.
510
511 Returns:
512 Response: FastAPI Response object with status 207.
513 """
514 return self.send_message_on_status(status=207, content=content, content_type=content_type, headers=headers)
515
516 def already_reported(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
517 """
518 Send a 208 Already Reported HTTP response.
519
520 WebDAV specific: indicates members of a DAV binding have already been
521 listed in a previous multi-status response and need not be repeated.
522 Helps reduce payload duplication in complex collection listings.
523
524 Args:
525 content (Any, optional): Optional explanatory payload. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
526 content_type (str, optional): Media type for the body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
527 headers (Mapping[str, str], optional): Extra response headers. Defaults to None.
528
529 Returns:
530 Response: FastAPI Response object with status 208.
531 """
532 return self.send_message_on_status(status=208, content=content, content_type=content_type, headers=headers)
533
534 def im_used(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
535 """
536 Send a 226 IM Used HTTP response.
537
538 Indicates the server fulfilled a GET using instance manipulations (e.g.,
539 delta encoding) applied to the current instance. Rarely used; applicable
540 when returning transformed representations rather than originals to
541 save bandwidth.
542
543 Args:
544 content (Any, optional): The manipulated representation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
545 content_type (str, optional): Media type for the body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
546 headers (Mapping[str, str], optional): Extra response headers detailing transformations. Defaults to None.
547
548 Returns:
549 Response: FastAPI Response object with status 226.
550 """
551 return self.send_message_on_status(status=226, content=content, content_type=content_type, headers=headers)
552
553 """ 3xx redirection """
554
555 def multiple_choices(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
556 """
557 Send a 300 Multiple Choices HTTP response.
558
559 Indicates multiple possible representations / endpoints for the resource
560 (e.g., different file formats or language variants). Provide a body or
561 headers (like `Link`) to guide client selection. Avoid if automated
562 negotiation can resolve the choice.
563
564 Args:
565 content (Any, optional): Description of available choices. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
566 content_type (str, optional): Media type for the body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
567 headers (Mapping[str, str], optional): Optional navigation metadata. Defaults to None.
568
569 Returns:
570 Response: FastAPI Response object with status 300.
571 """
572 return self.send_message_on_status(status=300, content=content, content_type=content_type, headers=headers)
573
574 def moved_permanently(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
575 """
576 Send a 301 Moved Permanently HTTP response.
577
578 Indicates the resource has a new canonical URI. Clients should update
579 bookmarks and future requests. Use for stable, long-term relocations.
580 Supply `Location` header pointing to the new URI.
581
582 Args:
583 content (Any, optional): Optional explanatory note. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
584 content_type (str, optional): Media type for the body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
585 headers (Mapping[str, str], optional): Should include a `Location` header. Defaults to None.
586
587 Returns:
588 Response: FastAPI Response object with status 301.
589 """
590 return self.send_message_on_status(status=301, content=content, content_type=content_type, headers=headers)
591
592 def found(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
593 """
594 Send a 302 Found (Temporary Redirect) HTTP response.
595
596 Historically ambiguous; modern semantics suggest temporary relocation.
597 Client should continue using original URI for future requests. Provide
598 `Location` header. Prefer 307 if preserving method matters.
599
600 Args:
601 content (Any, optional): Optional details about redirect. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
602 content_type (str, optional): Media type for the body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
603 headers (Mapping[str, str], optional): Include `Location`. Defaults to None.
604
605 Returns:
606 Response: FastAPI Response object with status 302.
607 """
608 return self.send_message_on_status(status=302, content=content, content_type=content_type, headers=headers)
609
610 def see_other(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
611 """
612 Send a 303 See Other HTTP response.
613
614 Directs client to retrieve a representation from a different URI using
615 GET. Common after POST to show resulting resource or status page.
616 Include `Location` header.
617
618 Args:
619 content (Any, optional): Optional redirect explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
620 content_type (str, optional): Media type for body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
621 headers (Mapping[str, str], optional): Should include `Location`. Defaults to None.
622
623 Returns:
624 Response: FastAPI Response object with status 303.
625 """
626 return self.send_message_on_status(status=303, content=content, content_type=content_type, headers=headers)
627
628 def not_modified(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
629 """
630 Send a 304 Not Modified HTTP response.
631
632 Indicates conditional GET found resource unchanged; client should use
633 cached version. Do not include a body. Must accompany relevant caching
634 headers (ETag / Last-Modified previously supplied).
635
636 Args:
637 content (Any, optional): Ignored; body omitted. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
638 content_type (str, optional): Ignored. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
639 headers (Mapping[str, str], optional): May include cache validators. Defaults to None.
640
641 Returns:
642 Response: FastAPI Response object with status 304.
643 """
644 return self.send_message_on_status(status=304, content=content, content_type=content_type, headers=headers)
645
646 def use_proxy(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
647 """
648 Send a 305 Use Proxy HTTP response.
649
650 Deprecated in modern HTTP; originally indicated resource must be
651 accessed through a specified proxy. Avoid using; retain only for legacy
652 compatibility contexts.
653
654 Args:
655 content (Any, optional): Advisory note. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
656 content_type (str, optional): Media type for body. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
657 headers (Mapping[str, str], optional): Legacy metadata. Defaults to None.
658
659 Returns:
660 Response: FastAPI Response object with status 305.
661 """
662 return self.send_message_on_status(status=305, content=content, content_type=content_type, headers=headers)
663
664 def switch_proxy(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
665 """
666 Send a 306 Switch Proxy HTTP response.
667
668 Reserved / unused status code kept for historical reasons. Should not
669 appear in new applications. Provided here for completeness.
670
671 Args:
672 content (Any, optional): Typically empty. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
673 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
674 headers (Mapping[str, str], optional): Headers map. Defaults to None.
675
676 Returns:
677 Response: FastAPI Response object with status 306.
678 """
679 return self.send_message_on_status(status=306, content=content, content_type=content_type, headers=headers)
680
681 def temporary_redirect(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
682 """
683 Send a 307 Temporary Redirect HTTP response.
684
685 Indicates resource temporarily at another URI; original method and body
686 must be reused. Safer than 302 for non-GET requests. Include `Location`.
687
688 Args:
689 content (Any, optional): Optional description. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
690 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
691 headers (Mapping[str, str], optional): Must include `Location`. Defaults to None.
692
693 Returns:
694 Response: FastAPI Response object with status 307.
695 """
696 return self.send_message_on_status(status=307, content=content, content_type=content_type, headers=headers)
697
698 def permanent_redirect(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
699 """
700 Send a 308 Permanent Redirect HTTP response.
701
702 Resource permanently moved; future requests should use new URI. Unlike
703 301, preserves method and body. Include `Location` header and migrate
704 clients accordingly.
705
706 Args:
707 content (Any, optional): Optional explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
708 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
709 headers (Mapping[str, str], optional): Should include `Location`. Defaults to None.
710
711 Returns:
712 Response: FastAPI Response object with status 308.
713 """
714 return self.send_message_on_status(status=308, content=content, content_type=content_type, headers=headers)
715
716 """ 4xx client error """
717
718 def bad_request(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
719 """
720 Send a 400 Bad Request HTTP response.
721
722 This response indicates that the server cannot process the request due to
723 client error (e.g., malformed request syntax, invalid request message framing,
724 or deceptive request routing).
725
726 Args:
727 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
728 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
729 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
730
731 Returns:
732 Response: A FastAPI Response object with status 400.
733 """
734 return self.send_message_on_status(status=400, content=content, content_type=content_type, headers=headers)
735
736 def unauthorized(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
737 """
738 Send a 401 Unauthorized HTTP response.
739
740 This response indicates that the request requires user authentication.
741 The client should authenticate itself to get the requested response.
742
743 Args:
744 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
745 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
746 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
747
748 Returns:
749 Response: A FastAPI Response object with status 401.
750 """
751 return self.send_message_on_status(status=401, content=content, content_type=content_type, headers=headers)
752
753 def payment_required(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
754 """
755 Send a 402 Payment Required HTTP response.
756
757 Reserved for future digital payment flows; occasionally repurposed for
758 quota or subscription enforcement. Provide actionable guidance for
759 completing payment or upgrading.
760
761 Args:
762 content (Any, optional): Payment or upgrade instructions. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
763 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
764 headers (Mapping[str, str], optional): May include billing references. Defaults to None.
765
766 Returns:
767 Response: FastAPI Response object with status 402.
768 """
769 return self.send_message_on_status(status=402, content=content, content_type=content_type, headers=headers)
770
771 def forbidden(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
772 """
773 Send a 403 Forbidden HTTP response.
774
775 Indicates authenticated client lacks permission for the target resource.
776 Use for authorization failures (role / ACL issues). Do not reveal
777 sensitive existence details beyond necessity.
778
779 Args:
780 content (Any, optional): Permission denial explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
781 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
782 headers (Mapping[str, str], optional): Additional security headers. Defaults to None.
783
784 Returns:
785 Response: FastAPI Response object with status 403.
786 """
787 return self.send_message_on_status(status=403, content=content, content_type=content_type, headers=headers)
788
789 def not_found(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
790 """
791 Send a 404 Not Found HTTP response.
792
793 Indicates the server cannot locate the target resource. Use for missing
794 identifiers, deleted objects, or invalid routes. Avoid leaking internal
795 structure; keep messages generic for security-sensitive contexts.
796
797 Args:
798 content (Any, optional): User-facing explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
799 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
800 headers (Mapping[str, str], optional): Headers map. Defaults to None.
801
802 Returns:
803 Response: FastAPI Response object with status 404.
804 """
805 return self.send_message_on_status(status=404, content=content, content_type=content_type, headers=headers)
806
807 def method_not_allowed(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
808 """
809 Send a 405 Method Not Allowed HTTP response.
810
811 Method exists but is not permitted for this resource (e.g., POST on a
812 read-only endpoint). Include an `Allow` header enumerating supported
813 methods.
814
815 Args:
816 content (Any, optional): Optional guidance. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
817 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
818 headers (Mapping[str, str], optional): Should include `Allow`. Defaults to None.
819
820 Returns:
821 Response: FastAPI Response object with status 405.
822 """
823 return self.send_message_on_status(status=405, content=content, content_type=content_type, headers=headers)
824
825 def not_acceptable(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
826 """
827 Send a 406 Not Acceptable HTTP response.
828
829 Indicates server cannot produce a representation matching client's
830 proactive content negotiation headers. Suggest alternative formats when
831 possible.
832
833 Args:
834 content (Any, optional): Negotiation failure details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
835 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
836 headers (Mapping[str, str], optional): May include `Vary`. Defaults to None.
837
838 Returns:
839 Response: FastAPI Response object with status 406.
840 """
841 return self.send_message_on_status(status=406, content=content, content_type=content_type, headers=headers)
842
843 def proxy_authentication_required(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
844 """
845 Send a 407 Proxy Authentication Required HTTP response.
846
847 Client must authenticate with a proxy before request can proceed.
848 Include `Proxy-Authenticate` challenge. Similar flow to 401 but for
849 intermediary.
850
851 Args:
852 content (Any, optional): Challenge/description. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
853 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
854 headers (Mapping[str, str], optional): Should include `Proxy-Authenticate`. Defaults to None.
855
856 Returns:
857 Response: FastAPI Response object with status 407.
858 """
859 return self.send_message_on_status(status=407, content=content, content_type=content_type, headers=headers)
860
861 def request_timeout(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
862 """
863 Send a 408 Request Timeout HTTP response.
864
865 Server terminated an idle connection because the client did not produce
866 a complete request in time. Client may retry. Consider adjusting timeouts
867 for large uploads.
868
869 Args:
870 content (Any, optional): Timeout explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
871 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
872 headers (Mapping[str, str], optional): Headers map. Defaults to None.
873
874 Returns:
875 Response: FastAPI Response object with status 408.
876 """
877 return self.send_message_on_status(status=408, content=content, content_type=content_type, headers=headers)
878
879 def conflict(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
880 """
881 Send a 409 Conflict HTTP response.
882
883 Indicates request conflicts with current resource state (e.g., version
884 mismatch, duplicate unique field). Provide resolution instructions or a
885 representation of the current state.
886
887 Args:
888 content (Any, optional): Conflict description. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
889 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
890 headers (Mapping[str, str], optional): May include `ETag`. Defaults to None.
891
892 Returns:
893 Response: FastAPI Response object with status 409.
894 """
895 return self.send_message_on_status(status=409, content=content, content_type=content_type, headers=headers)
896
897 def gone(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
898 """
899 Send a 410 Gone HTTP response.
900
901 Resource intentionally removed and no forwarding address known. Different
902 from 404 by permanence. Useful for deprecated APIs or purged content.
903
904 Args:
905 content (Any, optional): Removal explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
906 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
907 headers (Mapping[str, str], optional): Headers map. Defaults to None.
908
909 Returns:
910 Response: FastAPI Response object with status 410.
911 """
912 return self.send_message_on_status(status=410, content=content, content_type=content_type, headers=headers)
913
914 def length_required(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
915 """
916 Send a 411 Length Required HTTP response.
917
918 Server refuses request without a valid `Content-Length` header when one
919 is mandated. Client should resend with explicit length.
920
921 Args:
922 content (Any, optional): Instruction to include length. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
923 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
924 headers (Mapping[str, str], optional): Headers map. Defaults to None.
925
926 Returns:
927 Response: FastAPI Response object with status 411.
928 """
929 return self.send_message_on_status(status=411, content=content, content_type=content_type, headers=headers)
930
931 def precondition_failed(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
932 """
933 Send a 412 Precondition Failed HTTP response.
934
935 One or more conditional request headers (If-Match, If-Unmodified-Since)
936 did not match resource state, aborting the operation. Client should
937 refetch representation and retry.
938
939 Args:
940 content (Any, optional): Failed condition explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
941 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
942 headers (Mapping[str, str], optional): May include updated validators. Defaults to None.
943
944 Returns:
945 Response: FastAPI Response object with status 412.
946 """
947 return self.send_message_on_status(status=412, content=content, content_type=content_type, headers=headers)
948
949 def payload_too_large(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
950 """
951 Send a 413 Payload Too Large HTTP response.
952
953 Request entity exceeds server limits (size caps, upload restrictions).
954 Provide maximum allowed size to assist client correction.
955
956 Args:
957 content (Any, optional): Size limit details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
958 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
959 headers (Mapping[str, str], optional): May include limit hints. Defaults to None.
960
961 Returns:
962 Response: FastAPI Response object with status 413.
963 """
964 return self.send_message_on_status(status=413, content=content, content_type=content_type, headers=headers)
965
966 def uri_too_long(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
967 """
968 Send a 414 URI Too Long HTTP response.
969
970 Target URI exceeds server parsing or policy limits (often due to huge
971 query strings). Recommend switching to POST with body parameters.
972
973 Args:
974 content (Any, optional): Advisory message. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
975 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
976 headers (Mapping[str, str], optional): Headers map. Defaults to None.
977
978 Returns:
979 Response: FastAPI Response object with status 414.
980 """
981 return self.send_message_on_status(status=414, content=content, content_type=content_type, headers=headers)
982
983 def unsupported_media_type(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
984 """
985 Send a 415 Unsupported Media Type HTTP response.
986
987 Request's `Content-Type` not supported for target resource (e.g., image
988 upload in unsupported format). List accepted types where feasible.
989
990 Args:
991 content (Any, optional): Supported formats guidance. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
992 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
993 headers (Mapping[str, str], optional): May include `Accept-Post`. Defaults to None.
994
995 Returns:
996 Response: FastAPI Response object with status 415.
997 """
998 return self.send_message_on_status(status=415, content=content, content_type=content_type, headers=headers)
999
1000 def range_not_satisfiable(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1001 """
1002 Send a 416 Range Not Satisfiable HTTP response.
1003
1004 Client requested a byte range outside resource bounds. Include a
1005 `Content-Range` header indicating valid size to guide retries.
1006
1007 Args:
1008 content (Any, optional): Range error details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1009 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1010 headers (Mapping[str, str], optional): Should include `Content-Range`. Defaults to None.
1011
1012 Returns:
1013 Response: FastAPI Response object with status 416.
1014 """
1015 return self.send_message_on_status(status=416, content=content, content_type=content_type, headers=headers)
1016
1017 def expectation_failed(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1018 """
1019 Send a 417 Expectation Failed HTTP response.
1020
1021 Server cannot meet requirements of the `Expect` request-header (commonly
1022 `100-continue`). Client should adjust headers or remove Expect.
1023
1024 Args:
1025 content (Any, optional): Explanation of unmet expectation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1026 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1027 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1028
1029 Returns:
1030 Response: FastAPI Response object with status 417.
1031 """
1032 return self.send_message_on_status(status=417, content=content, content_type=content_type, headers=headers)
1033
1034 def im_a_teapot(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1035 """
1036 Send a 418 I'm a Teapot HTTP response.
1037
1038 April Fools RFC (RFC 2324) humorous code. Occasionally used for rate
1039 limiting or easter eggs. Avoid in production protocols unless intentional.
1040
1041 Args:
1042 content (Any, optional): Playful message. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1043 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1044 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1045
1046 Returns:
1047 Response: FastAPI Response object with status 418.
1048 """
1049 return self.send_message_on_status(status=418, content=content, content_type=content_type, headers=headers)
1050
1051 def page_expired(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1052 """
1053 Send a 419 Page Expired HTTP response.
1054
1055 Non-standard code sometimes used to indicate expired session or CSRF
1056 token invalidation. Provide re-authentication or refresh guidance.
1057
1058 Args:
1059 content (Any, optional): Expiration details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1060 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1061 headers (Mapping[str, str], optional): May include session hints. Defaults to None.
1062
1063 Returns:
1064 Response: FastAPI Response object with status 419.
1065 """
1066 return self.send_message_on_status(status=419, content=content, content_type=content_type, headers=headers)
1067
1068 def enhance_your_calm(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1069 """
1070 Send a 420 Enhance Your Calm HTTP response.
1071
1072 Non-standard (Twitter usage) for rate limiting or abuse detection.
1073 Provide throttling window and retry-after guidance where possible.
1074
1075 Args:
1076 content (Any, optional): Rate limit explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1077 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1078 headers (Mapping[str, str], optional): May include `Retry-After`. Defaults to None.
1079
1080 Returns:
1081 Response: FastAPI Response object with status 420.
1082 """
1083 return self.send_message_on_status(status=420, content=content, content_type=content_type, headers=headers)
1084
1085 def misdirected_request(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1086 """
1087 Send a 421 Misdirected Request HTTP response.
1088
1089 Request was directed to a server incapable of producing a response (e.g.,
1090 SNI routing mismatch). Client should retry against correct origin.
1091
1092 Args:
1093 content (Any, optional): Routing error details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1094 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1095 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1096
1097 Returns:
1098 Response: FastAPI Response object with status 421.
1099 """
1100 return self.send_message_on_status(status=421, content=content, content_type=content_type, headers=headers)
1101
1102 def unprocessable_entity(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1103 """
1104 Send a 422 Unprocessable Entity HTTP response.
1105
1106 Syntax is correct but semantic validation failed (e.g., domain rules,
1107 constraint violations). Return structured field error details to aid
1108 client correction.
1109
1110 Args:
1111 content (Any, optional): Validation errors payload. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1112 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1113 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1114
1115 Returns:
1116 Response: FastAPI Response object with status 422.
1117 """
1118 return self.send_message_on_status(status=422, content=content, content_type=content_type, headers=headers)
1119
1120 def locked(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1121 """
1122 Send a 423 Locked HTTP response.
1123
1124 WebDAV: resource is locked and cannot be modified. Provide lock token or
1125 instructions for obtaining access if appropriate.
1126
1127 Args:
1128 content (Any, optional): Lock state description. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1129 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1130 headers (Mapping[str, str], optional): May include lock token reference. Defaults to None.
1131
1132 Returns:
1133 Response: FastAPI Response object with status 423.
1134 """
1135 return self.send_message_on_status(status=423, content=content, content_type=content_type, headers=headers)
1136
1137 def failed_dependency(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1138 """
1139 Send a 424 Failed Dependency HTTP response.
1140
1141 WebDAV: a method failed because a prior request on which it depended
1142 failed. Use in batch or chained operations to clarify cascading errors.
1143
1144 Args:
1145 content (Any, optional): Upstream failure details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1146 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1147 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1148
1149 Returns:
1150 Response: FastAPI Response object with status 424.
1151 """
1152 return self.send_message_on_status(status=424, content=content, content_type=content_type, headers=headers)
1153
1154 def too_early(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1155 """
1156 Send a 425 Too Early HTTP response.
1157
1158 Indicates server is unwilling to risk replay of a request that might be
1159 unsafe if repeated (e.g., early data in TLS 1.3). Client should resend
1160 without early data.
1161
1162 Args:
1163 content (Any, optional): Replay risk explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1164 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1165 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1166
1167 Returns:
1168 Response: FastAPI Response object with status 425.
1169 """
1170 return self.send_message_on_status(status=425, content=content, content_type=content_type, headers=headers)
1171
1172 def upgrade_required(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1173 """
1174 Send a 426 Upgrade Required HTTP response.
1175
1176 Client must switch to a different protocol (e.g., TLS, HTTP/2) to proceed.
1177 Include `Upgrade` header advertising acceptable protocols.
1178
1179 Args:
1180 content (Any, optional): Upgrade instructions. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1181 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1182 headers (Mapping[str, str], optional): Should include `Upgrade`. Defaults to None.
1183
1184 Returns:
1185 Response: FastAPI Response object with status 426.
1186 """
1187 return self.send_message_on_status(status=426, content=content, content_type=content_type, headers=headers)
1188
1189 def precondition_required(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1190 """
1191 Send a 428 Precondition Required HTTP response.
1192
1193 Server requires the request be conditional (e.g., to prevent lost updates
1194 in concurrent modifications). Client should include appropriate
1195 conditional headers (If-Match / If-Unmodified-Since).
1196
1197 Args:
1198 content (Any, optional): Instruction to add conditions. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1199 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1200 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1201
1202 Returns:
1203 Response: FastAPI Response object with status 428.
1204 """
1205 return self.send_message_on_status(status=428, content=content, content_type=content_type, headers=headers)
1206
1207 def too_many_requests(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1208 """
1209 Send a 429 Too Many Requests HTTP response.
1210
1211 Rate limiting triggered. Provide retry guidance via `Retry-After` or
1212 quota headers. Distinguish per-user vs global limits where relevant.
1213
1214 Args:
1215 content (Any, optional): Throttling explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1216 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1217 headers (Mapping[str, str], optional): Include rate limit metadata. Defaults to None.
1218
1219 Returns:
1220 Response: FastAPI Response object with status 429.
1221 """
1222 return self.send_message_on_status(status=429, content=content, content_type=content_type, headers=headers)
1223
1224 def request_header_fields_too_large(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1225 """
1226 Send a 431 Request Header Fields Too Large HTTP response.
1227
1228 One or more header fields exceed size limits (security or performance
1229 constraints). Client should reduce header volume (cookies, custom
1230 metadata) and retry.
1231
1232 Args:
1233 content (Any, optional): Reduction guidance. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1234 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1235 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1236
1237 Returns:
1238 Response: FastAPI Response object with status 431.
1239 """
1240 return self.send_message_on_status(status=431, content=content, content_type=content_type, headers=headers)
1241
1242 def unavailable_for_legal_reasons(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1243 """
1244 Send a 451 Unavailable For Legal Reasons HTTP response.
1245
1246 Resource unavailable due to legal demands (e.g., censorship, DMCA). Keep
1247 explanation minimal yet transparent. Avoid exposing sensitive legal
1248 references publicly.
1249
1250 Args:
1251 content (Any, optional): Legal restriction notice. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1252 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1253 headers (Mapping[str, str], optional): May include policy links. Defaults to None.
1254
1255 Returns:
1256 Response: FastAPI Response object with status 451.
1257 """
1258 return self.send_message_on_status(status=451, content=content, content_type=content_type, headers=headers)
1259
1260 def invalid_token(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1261 """
1262 Send a 498 Invalid Token HTTP response.
1263
1264 Non-standard code occasionally used when token (API key / session) is
1265 malformed or expired but distinct from 401 semantics. Provide refresh
1266 / re-authentication instructions.
1267
1268 Args:
1269 content (Any, optional): Token validity explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1270 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1271 headers (Mapping[str, str], optional): May include security hints. Defaults to None.
1272
1273 Returns:
1274 Response: FastAPI Response object with status 498.
1275 """
1276 return self.send_message_on_status(status=498, content=content, content_type=content_type, headers=headers)
1277
1278 """ 5xx server error"""
1279
1280 def internal_server_error(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1281 """
1282 Send a 500 Internal Server Error HTTP response.
1283
1284 This response indicates that the server encountered an unexpected condition
1285 that prevented it from fulfilling the request.
1286
1287 Args:
1288 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1289 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1290 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
1291
1292 Returns:
1293 Response: A FastAPI Response object with status 500.
1294 """
1295 return self.send_message_on_status(status=500, content=content, content_type=content_type, headers=headers)
1296
1297 def not_implemented(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1298 """
1299 Send a 501 Not Implemented HTTP response.
1300
1301 This response indicates that the server does not support the functionality
1302 required to fulfill the request.
1303
1304 Args:
1305 content (Any, optional): The content to send. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1306 content_type (ContentTypeLike, optional): Content type as `DataTypes` member, known key (e.g., "json"), or raw MIME string. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1307 headers (Mapping[str, str], optional): Additional headers to include. Defaults to None.
1308
1309 Returns:
1310 Response: A FastAPI Response object with status 501.
1311 """
1312 return self.send_message_on_status(status=501, content=content, content_type=content_type, headers=headers)
1313
1314 def bad_gateway(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1315 """
1316 Send a 502 Bad Gateway HTTP response.
1317
1318 Upstream server returned an invalid / error response to a gateway or
1319 proxy. Client may retry; investigate upstream health. Include minimal
1320 diagnostic context if safe.
1321
1322 Args:
1323 content (Any, optional): Upstream failure summary. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1324 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1325 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1326
1327 Returns:
1328 Response: FastAPI Response object with status 502.
1329 """
1330 return self.send_message_on_status(status=502, content=content, content_type=content_type, headers=headers)
1331
1332 def service_unavailable(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1333 """
1334 Send a 503 Service Unavailable HTTP response.
1335
1336 Server temporarily unable to handle the request (maintenance / overload).
1337 Provide `Retry-After` if known. Differentiate transient from permanent
1338 failure states.
1339
1340 Args:
1341 content (Any, optional): Downtime notice. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1342 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1343 headers (Mapping[str, str], optional): May include `Retry-After`. Defaults to None.
1344
1345 Returns:
1346 Response: FastAPI Response object with status 503.
1347 """
1348 return self.send_message_on_status(status=503, content=content, content_type=content_type, headers=headers)
1349
1350 def gateway_timeout(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1351 """
1352 Send a 504 Gateway Timeout HTTP response.
1353
1354 Upstream server failed to respond in time to a gateway / proxy. Client
1355 may retry with backoff. Monitor latency and circuit breaker thresholds.
1356
1357 Args:
1358 content (Any, optional): Timeout context. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1359 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1360 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1361
1362 Returns:
1363 Response: FastAPI Response object with status 504.
1364 """
1365 return self.send_message_on_status(status=504, content=content, content_type=content_type, headers=headers)
1366
1367 def http_version_not_supported(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1368 """
1369 Send a 505 HTTP Version Not Supported HTTP response.
1370
1371 Server rejects requested HTTP protocol version. Advise supported versions
1372 (e.g., HTTP/1.1, HTTP/2). Could imply need for TLS upgrade pathway.
1373
1374 Args:
1375 content (Any, optional): Supported version info. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1376 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1377 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1378
1379 Returns:
1380 Response: FastAPI Response object with status 505.
1381 """
1382 return self.send_message_on_status(status=505, content=content, content_type=content_type, headers=headers)
1383
1384 def variant_also_negotiates(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1385 """
1386 Send a 506 Variant Also Negotiates HTTP response.
1387
1388 Internal configuration error: content negotiation process is itself
1389 negotiated recursively. Rare; indicates misconfigured server variant
1390 selection logic.
1391
1392 Args:
1393 content (Any, optional): Diagnostic hint. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1394 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1395 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1396
1397 Returns:
1398 Response: FastAPI Response object with status 506.
1399 """
1400 return self.send_message_on_status(status=506, content=content, content_type=content_type, headers=headers)
1401
1402 def insufficient_storage(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1403 """
1404 Send a 507 Insufficient Storage HTTP response.
1405
1406 WebDAV / extension: server cannot store the representation needed to
1407 complete the request. Suggest freeing space or upgrading quotas.
1408
1409 Args:
1410 content (Any, optional): Storage limitation explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1411 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1412 headers (Mapping[str, str], optional): May include quota metadata. Defaults to None.
1413
1414 Returns:
1415 Response: FastAPI Response object with status 507.
1416 """
1417 return self.send_message_on_status(status=507, content=content, content_type=content_type, headers=headers)
1418
1419 def loop_detected(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1420 """
1421 Send a 508 Loop Detected HTTP response.
1422
1423 WebDAV: infinite loop encountered while processing a request (e.g.,
1424 cyclic bindings). Client should adjust request path or structure.
1425
1426 Args:
1427 content (Any, optional): Loop diagnostic. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1428 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1429 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1430
1431 Returns:
1432 Response: FastAPI Response object with status 508.
1433 """
1434 return self.send_message_on_status(status=508, content=content, content_type=content_type, headers=headers)
1435
1436 def bandwidth_limit_exceeded(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1437 """
1438 Send a 509 Bandwidth Limit Exceeded HTTP response.
1439
1440 Non-standard: hosting provider quota surpassed. Provide reset window or
1441 upgrade path. Distinguish from transient network congestion.
1442
1443 Args:
1444 content (Any, optional): Bandwidth quota details. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1445 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1446 headers (Mapping[str, str], optional): May include usage metrics. Defaults to None.
1447
1448 Returns:
1449 Response: FastAPI Response object with status 509.
1450 """
1451 return self.send_message_on_status(status=509, content=content, content_type=content_type, headers=headers)
1452
1453 def not_extended(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1454 """
1455 Send a 510 Not Extended HTTP response.
1456
1457 Further extensions to the request are required for it to be fulfilled
1458 (e.g., additional protocol capabilities). Rare; provide explicit next
1459 steps.
1460
1461 Args:
1462 content (Any, optional): Extension requirement explanation. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1463 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1464 headers (Mapping[str, str], optional): Headers map. Defaults to None.
1465
1466 Returns:
1467 Response: FastAPI Response object with status 510.
1468 """
1469 return self.send_message_on_status(status=510, content=content, content_type=content_type, headers=headers)
1470
1471 def network_authentication_required(self, content: Any = CONST.DEFAULT_MESSAGE_CONTENT, *, content_type: ContentTypeLike = CONST.DEFAULT_MESSAGE_TYPE, headers: Optional[Mapping[str, str]] = None) -> Response:
1472 """
1473 Send a 511 Network Authentication Required HTTP response.
1474
1475 Client must authenticate to gain network access (e.g., captive portal).
1476 Provide login or acceptance instructions. After completion, original
1477 request can be retried.
1478
1479 Args:
1480 content (Any, optional): Network access instructions. Defaults to CONST.DEFAULT_MESSAGE_CONTENT.
1481 content_type (str, optional): Media type. Defaults to CONST.DEFAULT_MESSAGE_TYPE.
1482 headers (Mapping[str, str], optional): May include portal references. Defaults to None.
1483
1484 Returns:
1485 Response: FastAPI Response object with status 511.
1486 """
1487 return self.send_message_on_status(status=511, content=content, content_type=content_type, headers=headers)
1488
1489
1490HCI = HttpCodes()
Response multi_status(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response upgrade_required(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response switch_proxy(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response multiple_choices(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response send_message_on_status(self, int status=200, Any content=CONST.DEFAULT_MESSAGE_CONTENT, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Any _check_header(self, Optional[Mapping[str, str]] header=None)
Definition http_codes.py:95
Response precondition_failed(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response request_header_fields_too_large(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response early_hints(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response gone(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response send_continue(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response uri_too_long(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response invalid_token(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response locked(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response too_early(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response processing(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response switching_protocols(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response temporary_redirect(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response request_timeout(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response unauthorized(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response moved_permanently(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response not_acceptable(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response payment_required(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response proxy_authentication_required(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response already_reported(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response non_authoritative_information(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response range_not_satisfiable(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response precondition_required(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response response_is_stale(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response conflict(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response unavailable_for_legal_reasons(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response failed_dependency(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response misdirected_request(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Any _process_data_content(self, Any data, str data_type)
Response expectation_failed(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response bad_request(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response unsupported_media_type(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response no_content(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response reset_content(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response created(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response im_used(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Union[Response, FileResponse, HTMLResponse, JSONResponse, PlainTextResponse, RedirectResponse, StreamingResponse, UJSONResponse, ORJSONResponse] _package_correctly(self, int status=200, Any content=CONST.DEFAULT_MESSAGE_CONTENT, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response too_many_requests(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response permanent_redirect(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response payload_too_large(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response enhance_your_calm(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response found(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response use_proxy(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response forbidden(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response unprocessable_entity(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response see_other(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response not_modified(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response success(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response partial_content(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
str _check_data_type(self, Optional[ContentTypeLike] data_type=None)
Definition http_codes.py:62
Response length_required(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response page_expired(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response accepted(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response im_a_teapot(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response not_found(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)
Response method_not_allowed(self, Any content=CONST.DEFAULT_MESSAGE_CONTENT, *, ContentTypeLike content_type=CONST.DEFAULT_MESSAGE_TYPE, Optional[Mapping[str, str]] headers=None)