MCPcopy Index your code
hub / github.com/adafruit/Adafruit_CircuitPython_HTTPServer / poll

Method poll

adafruit_httpserver/server.py:463–533  ·  view source on GitHub ↗

Call this method inside your main loop to get the server to check for new incoming client requests. When a request comes in, it will be handled by the handler function. Returns str representing the result of the poll e.g. ``NO_REQUEST`` or ``REQUEST_HANDLED_RESPONSE

(
        self,
    )

Source from the content-addressed store, hash-verified

461 response._headers.setdefault(name, value)
462
463 def poll(
464 self,
465 ) -> str:
466 """
467 Call this method inside your main loop to get the server to check for new incoming client
468 requests. When a request comes in, it will be handled by the handler function.
469
470 Returns str representing the result of the poll
471 e.g. ``NO_REQUEST`` or ``REQUEST_HANDLED_RESPONSE_SENT``.
472 """
473 if self.stopped:
474 raise ServerStoppedError
475
476 conn = None
477 try:
478 if self.debug:
479 _debug_start_time = monotonic()
480
481 conn, client_address = self._sock.accept()
482 conn.settimeout(self._timeout)
483
484 # Receive the whole request
485 if (request := self._receive_request(conn, client_address)) is None:
486 conn.close()
487 return CONNECTION_TIMED_OUT
488
489 # Find a route that matches the request's method and path and get its handler
490 handler = self._find_handler(request.method, request.path)
491
492 # Handle the request
493 response = self._handle_request(request, handler)
494
495 if response is None:
496 conn.close()
497 return REQUEST_HANDLED_NO_RESPONSE
498
499 self._set_default_server_headers(response)
500
501 # Send the response
502 response._send()
503
504 if self.debug:
505 _debug_end_time = monotonic()
506 _debug_response_sent(response, _debug_end_time - _debug_start_time)
507
508 return REQUEST_HANDLED_RESPONSE_SENT
509
510 except Exception as error:
511 if isinstance(error, OSError):
512 # There is no data available right now, try again later.
513 if error.errno == EAGAIN:
514 return NO_REQUEST
515 # Connection reset by peer, try again later.
516 if error.errno == ECONNRESET:
517 return NO_REQUEST
518 # Handshake failed, try again later.
519 if error.errno == MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE:
520 return NO_REQUEST

Callers 7

serve_foreverMethod · 0.95
httpserver_sse.pyFile · 0.80
handle_http_requestsFunction · 0.80
handle_http_requestsFunction · 0.80
handle_http_requestsFunction · 0.80

Calls 10

_receive_requestMethod · 0.95
_find_handlerMethod · 0.95
_handle_requestMethod · 0.95
_debug_response_sentFunction · 0.85
acceptMethod · 0.80
settimeoutMethod · 0.80
closeMethod · 0.45
_sendMethod · 0.45

Tested by

no test coverage detected