diff --git a/adafruit_httpserver.py b/adafruit_httpserver.py index 206375d..28dad98 100644 --- a/adafruit_httpserver.py +++ b/adafruit_httpserver.py @@ -174,7 +174,7 @@ def mime_type(filename): class HTTPResponse: - """Details of an HTTP response. Use in @`HTTPServer.route` decorator functions.""" + """Details of an HTTP response. Use in `HTTPServer.route` decorator functions.""" _HEADERS_FORMAT = ( "HTTP/1.1 {}\r\n" @@ -361,3 +361,25 @@ def poll(self): # connection reset by peer, try again later. return raise + + @property + def request_buffer_size(self) -> int: + """ + The maximum size of the incoming request buffer. If the default size isn't + adequate to handle your incoming data you can set this after creating the + server instance. + + Default size is 1024 bytes. + + Example:: + + server = HTTPServer(pool) + server.request_buffer_size = 2048 + + server.serve_forever(str(wifi.radio.ipv4_address)) + """ + return len(self._buffer) + + @request_buffer_size.setter + def request_buffer_size(self, value: int) -> None: + self._buffer = bytearray(value) diff --git a/docs/examples.rst b/docs/examples.rst index 336dd2c..0100e37 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,22 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/httpserver_simpletest.py :caption: examples/httpserver_simpletest.py :linenos: + +Temperature test +-------------------- + +Send the microcontroller temperature back to the browser with this simple test. + +.. literalinclude:: ../examples/httpserver_temperature.py + :caption: examples/httpserver_temperature.py + :linenos: + +Simple polling test +------------------- + +If you want your code to do more than just serve web pages, +use the start/poll methods as shown in this example. + +.. literalinclude:: ../examples/httpserver_simplepolling.py + :caption: examples/httpserver_simplepolling.py + :linenos: diff --git a/examples/httpserver_simplepolling.py b/examples/httpserver_simplepolling.py index 12211fc..6bec7e8 100644 --- a/examples/httpserver_simplepolling.py +++ b/examples/httpserver_simplepolling.py @@ -30,7 +30,11 @@ def base(request): # pylint: disable=unused-argument while True: try: - # processing any waiting requests + # do something useful in this section, + # for example read a sensor and capture an average, + # or a running total of the last 10 samples + + # process any waiting requests server.poll() except OSError: continue