@@ -49,11 +49,11 @@ In order to save memory, we are unregistering unused MIME types and registering
4949 :linenos:
5050
5151You can also serve a specific file from the handler.
52- By default ``Response.send_file() `` looks for the file in the server's ``root_path `` directory, but you can change it.
52+ By default ``FileResponse `` looks for the file in the server's ``root_path `` directory, but you can change it.
5353
5454.. literalinclude :: ../examples/httpserver_handler_serves_file.py
5555 :caption: examples/httpserver_handler_serves_file.py
56- :emphasize-lines: 22-23
56+ :emphasize-lines: 22
5757 :linenos:
5858
5959.. literalinclude :: ../examples/home.html
@@ -74,7 +74,7 @@ a running total of the last 10 samples.
7474
7575.. literalinclude :: ../examples/httpserver_start_and_poll.py
7676 :caption: examples/httpserver_start_and_poll.py
77- :emphasize-lines: 25,34
77+ :emphasize-lines: 24,33
7878 :linenos:
7979
8080Server with MDNS
@@ -91,6 +91,17 @@ In this example, the server is accessible via ``http://custom-mdns-hostname/`` a
9191 :emphasize-lines: 12-14
9292 :linenos:
9393
94+ Get CPU information
95+ -------------------
96+
97+ You can return data from sensors or any computed value as JSON.
98+ That makes it easy to use the data in other applications.
99+
100+ .. literalinclude :: ../examples/httpserver_cpu_information.py
101+ :caption: examples/httpserver_cpu_information.py
102+ :emphasize-lines: 9,27
103+ :linenos:
104+
94105Handling different methods
95106---------------------------------------
96107
@@ -107,7 +118,7 @@ In example below, handler for ``/api`` and ``/api/`` route will be called when a
107118
108119.. literalinclude :: ../examples/httpserver_methods.py
109120 :caption: examples/httpserver_methods.py
110- :emphasize-lines: 8,15
121+ :emphasize-lines: 8,19,26,30,49
111122 :linenos:
112123
113124Change NeoPixel color
@@ -129,29 +140,19 @@ Tested on ESP32-S2 Feather.
129140
130141.. literalinclude :: ../examples/httpserver_neopixel.py
131142 :caption: examples/httpserver_neopixel.py
132- :emphasize-lines: 25-27,39-40,52-53,61,69
133- :linenos:
134-
135- Get CPU information
136- -------------------
137-
138- You can return data from sensors or any computed value as JSON.
139- That makes it easy to use the data in other applications.
140-
141- .. literalinclude :: ../examples/httpserver_cpu_information.py
142- :caption: examples/httpserver_cpu_information.py
143- :emphasize-lines: 28-29
143+ :emphasize-lines: 25-27,39,51,60,66
144144 :linenos:
145145
146146Chunked response
147147----------------
148148
149- Library supports chunked responses. This is useful for streaming data.
150- To use it, you need to set the ``chunked=True `` when creating a ``Response `` object.
149+ Library supports chunked responses. This is useful for streaming large amounts of data.
150+ In order to use it, you need pass a generator that yields chunks of data to a ``ChunkedResponse ``
151+ constructor.
151152
152153.. literalinclude :: ../examples/httpserver_chunked.py
153154 :caption: examples/httpserver_chunked.py
154- :emphasize-lines: 21-26
155+ :emphasize-lines: 8, 21-26,28
155156 :linenos:
156157
157158URL parameters and wildcards
@@ -163,7 +164,7 @@ Query/GET parameters are better suited for modifying the behaviour of the handle
163164
164165Of course it is only a suggestion, you can use them interchangeably and/or both at the same time.
165166
166- In order to use URL parameters, you need to wrap them inside `` <> `` in ``Server.route ``, e.g. ``<my_parameter> ``.
167+ In order to use URL parameters, you need to wrap them inside with angle brackets in ``Server.route ``, e.g. ``<my_parameter> ``.
167168
168169All URL parameters values are **passed as keyword arguments ** to the handler function.
169170
@@ -185,7 +186,7 @@ In both cases, wildcards will not match empty path segment, so ``/api/.../users`
185186
186187.. literalinclude :: ../examples/httpserver_url_parameters.py
187188 :caption: examples/httpserver_url_parameters.py
188- :emphasize-lines: 30-34,54-55
189+ :emphasize-lines: 30-34,53-54
189190 :linenos:
190191
191192Authentication
@@ -206,7 +207,21 @@ In both cases you can check if ``request`` is authenticated by calling ``check_a
206207
207208.. literalinclude :: ../examples/httpserver_authentication_handlers.py
208209 :caption: examples/httpserver_authentication_handlers.py
209- :emphasize-lines: 9-15,21-25,33,44,57
210+ :emphasize-lines: 9-15,21-25,33,47,59
211+ :linenos:
212+
213+ Redirects
214+ ---------
215+
216+ Sometimes you might want to redirect the user to a different URL, either on the same server or on a different one.
217+
218+ You can do that by returning ``Redirect `` from your handler function.
219+
220+ You can specify wheter the redirect is permanent or temporary by passing ``permanent=... `` to ``Redirect ``.
221+
222+ .. literalinclude :: ../examples/httpserver_redirects.py
223+ :caption: examples/httpserver_redirects.py
224+ :emphasize-lines: 14-18,26,38
210225 :linenos:
211226
212227Multiple servers
@@ -223,7 +238,7 @@ You can share same handler functions between servers or use different ones for e
223238
224239.. literalinclude :: ../examples/httpserver_multiple_servers.py
225240 :caption: examples/httpserver_multiple_servers.py
226- :emphasize-lines: 13-14,17,26,35-36,48-49,54-55
241+ :emphasize-lines: 13-14,17,25,33-34,45-46,51-52
227242 :linenos:
228243
229244Debug mode
@@ -256,8 +271,7 @@ This is the default format of the logs::
256271 {client_ip} -- "{request_method} {path}" {request_size} -- "{response_status}" {response_size}
257272
258273If you need more information about the server or request, or you want it in a different format you can modify
259- functions at the bottom of ``adafruit_httpserver/server.py `` and ``adafruit_httpserver/response.py `` that
260- start with ``_debug_... ``.
274+ functions at the bottom of ``adafruit_httpserver/server.py `` that start with ``_debug_... ``.
261275
262276NOTE:
263277*This is an advanced usage that might change in the future. It is not recommended to modify other parts of the code. *
0 commit comments