(self)
| 27 | self.end_headers() |
| 28 | |
| 29 | def _handle(self): |
| 30 | try: |
| 31 | # put_nowait is common between Queue & asyncio.Queue, it does not need to be awaited |
| 32 | self.server.queue.put_nowait(self.path) |
| 33 | header = self.headers["Authorization"] |
| 34 | if header is not None and "xoxp-" in header: |
| 35 | pattern = str(header).split("xoxp-", 1)[1] |
| 36 | if "remote_disconnected" in pattern: |
| 37 | # http.client.RemoteDisconnected |
| 38 | self.finish() |
| 39 | return |
| 40 | if "ratelimited" in pattern: |
| 41 | self.send_response(429) |
| 42 | self.send_header("retry-after", 1) |
| 43 | self.set_common_headers() |
| 44 | self.wfile.write("""{"ok": false, "error": "ratelimited"}""".encode("utf-8")) |
| 45 | return |
| 46 | |
| 47 | if self.is_valid_token() and self.is_valid_user_agent(): |
| 48 | self.send_response(HTTPStatus.OK) |
| 49 | self.set_common_headers() |
| 50 | self.wfile.close() |
| 51 | else: |
| 52 | self.send_response(HTTPStatus.BAD_REQUEST) |
| 53 | self.set_common_headers() |
| 54 | self.wfile.close() |
| 55 | |
| 56 | except Exception as e: |
| 57 | self.logger.error(str(e), exc_info=True) |
| 58 | raise |
| 59 | |
| 60 | def do_GET(self): |
| 61 | self._handle() |
no test coverage detected