-
-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(recipes): clean up recent recipe additions (+misc touchups) #2425
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
98da178
chore(AUTHORS): aggregate 4.1.0 contributors so far
vytas7 9ec5ad9
docs: happy new year
vytas7 a463a73
chore: remove carriage-returns (we only use LF for indentation)
vytas7 2ab64a8
docs(recipes): improve the plain text media handler recipe
vytas7 29786cc
docs(recipes): clean up request-id log recipes
vytas7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
.. _plain_text_handler_recipe: | ||
|
||
Handling Plain Text as Media | ||
============================ | ||
|
||
This example demonstrates how to create a custom handler in Falcon to | ||
process the ``text/plain`` media type. The handler implements serialization | ||
and deserialization of textual content, respecting the charset specified | ||
in the ``Content-Type`` header (or defaulting to ``utf-8`` when no charset is provided). | ||
|
||
.. literalinclude:: ../../../examples/recipes/plain_text_main.py | ||
:language: python | ||
|
||
To use this handler, register it in the Falcon application's media | ||
options for both request and response: | ||
|
||
.. code:: python | ||
|
||
import falcon | ||
from your_module import TextHandler | ||
|
||
app = falcon.App() | ||
app.req_options.media_handlers['text/plain'] = TextHandler() | ||
app.resp_options.media_handlers['text/plain'] = TextHandler() | ||
|
||
With this setup, the application can handle textual data directly | ||
as ``text/plain``, ensuring support for various character encodings as needed. | ||
|
||
.. warning:: | ||
Be sure to validate and limit the size of incoming data when | ||
working with textual content to prevent server overload or denial-of-service attacks. | ||
.. _plain_text_handler_recipe: | ||
|
||
Handling Plain Text as Media | ||
============================ | ||
|
||
Normally, it is easiest to render a plain text response by setting | ||
:attr:`resp.text <falcon.Response.text>` | ||
(see also: :ref:`resp_media_data_text`). | ||
However, if plain text is just one of | ||
the :ref:`Internet media types <media>` that your application speaks, it may be | ||
useful to generalize handling plain text as :ref:`media <media>` too. | ||
|
||
This recipe demonstrates how to create a | ||
:ref:`custom media handler <custom-media-handler-type>` to process the | ||
``text/plain`` media type. The handler implements serialization and | ||
deserialization of textual content, respecting the charset specified in the | ||
``Content-Type`` header | ||
(or defaulting to ``utf-8`` when no charset is provided). | ||
|
||
.. literalinclude:: ../../../examples/recipes/plain_text_main.py | ||
:language: python | ||
|
||
To use this handler, :ref:`register <custom_media_handlers>` it in the Falcon | ||
application's media options for both request and response: | ||
|
||
.. code:: python | ||
|
||
import falcon | ||
from your_module import TextHandler | ||
|
||
app = falcon.App() | ||
app.req_options.media_handlers['text/plain'] = TextHandler() | ||
app.resp_options.media_handlers['text/plain'] = TextHandler() | ||
|
||
With this setup, the application can handle textual data directly | ||
as ``text/plain``, ensuring support for various character encodings as needed. | ||
|
||
.. warning:: | ||
Be sure to validate and limit the size of incoming data when working with | ||
textual content to prevent server overload or denial-of-service attacks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# context.py | ||
|
||
import contextvars | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was originally contributed with CRLF line endings, whereas we use LF. Hence the total diff.