Skip to content

Commit 96b045b

Browse files
authored
Merge pull request #11 from karlfl/AddBufferSizeProperty
Add buffer size property
2 parents 3cc5ffb + 6528b68 commit 96b045b

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

adafruit_httpserver.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def mime_type(filename):
174174

175175

176176
class HTTPResponse:
177-
"""Details of an HTTP response. Use in @`HTTPServer.route` decorator functions."""
177+
"""Details of an HTTP response. Use in `HTTPServer.route` decorator functions."""
178178

179179
_HEADERS_FORMAT = (
180180
"HTTP/1.1 {}\r\n"
@@ -361,3 +361,25 @@ def poll(self):
361361
# connection reset by peer, try again later.
362362
return
363363
raise
364+
365+
@property
366+
def request_buffer_size(self) -> int:
367+
"""
368+
The maximum size of the incoming request buffer. If the default size isn't
369+
adequate to handle your incoming data you can set this after creating the
370+
server instance.
371+
372+
Default size is 1024 bytes.
373+
374+
Example::
375+
376+
server = HTTPServer(pool)
377+
server.request_buffer_size = 2048
378+
379+
server.serve_forever(str(wifi.radio.ipv4_address))
380+
"""
381+
return len(self._buffer)
382+
383+
@request_buffer_size.setter
384+
def request_buffer_size(self, value: int) -> None:
385+
self._buffer = bytearray(value)

docs/examples.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,22 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/httpserver_simpletest.py
77
:caption: examples/httpserver_simpletest.py
88
:linenos:
9+
10+
Temperature test
11+
--------------------
12+
13+
Send the microcontroller temperature back to the browser with this simple test.
14+
15+
.. literalinclude:: ../examples/httpserver_temperature.py
16+
:caption: examples/httpserver_temperature.py
17+
:linenos:
18+
19+
Simple polling test
20+
-------------------
21+
22+
If you want your code to do more than just serve web pages,
23+
use the start/poll methods as shown in this example.
24+
25+
.. literalinclude:: ../examples/httpserver_simplepolling.py
26+
:caption: examples/httpserver_simplepolling.py
27+
:linenos:

examples/httpserver_simplepolling.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def base(request): # pylint: disable=unused-argument
3030

3131
while True:
3232
try:
33-
# processing any waiting requests
33+
# do something useful in this section,
34+
# for example read a sensor and capture an average,
35+
# or a running total of the last 10 samples
36+
37+
# process any waiting requests
3438
server.poll()
3539
except OSError:
3640
continue

0 commit comments

Comments
 (0)