diff options
| author | Joshua Watt <JPEWhacker@gmail.com> | 2024-02-22 15:31:48 -0700 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-02-27 11:36:38 +0000 |
| commit | be57fda5423eae49133fa0fdecaa30e4d9f57026 (patch) | |
| tree | 8802ac653d428463db3e3941d6a4c796152d8be0 /bitbake/lib/bb/asyncrpc/serv.py | |
| parent | 28414495277e87898c9ac5314b88ebb747494dac (diff) | |
| download | poky-be57fda5423eae49133fa0fdecaa30e4d9f57026.tar.gz | |
bitbake: asyncrpc: Add support for server headers
Adds support for asyncrpc servers to send connection headers to clients
on connection. Since this is a breaking protocol change, clients must
opt-in to expect headers from the server, corresponding to a version
bump in the client protocol.
(Bitbake rev: 1cb2b8be6cc5269553f549285592e47b7d29db03)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/asyncrpc/serv.py')
| -rw-r--r-- | bitbake/lib/bb/asyncrpc/serv.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/bitbake/lib/bb/asyncrpc/serv.py b/bitbake/lib/bb/asyncrpc/serv.py index f0be9a6cdb..a66117acad 100644 --- a/bitbake/lib/bb/asyncrpc/serv.py +++ b/bitbake/lib/bb/asyncrpc/serv.py | |||
| @@ -39,10 +39,14 @@ class AsyncServerConnection(object): | |||
| 39 | "address": socket.address, | 39 | "address": socket.address, |
| 40 | }, | 40 | }, |
| 41 | ) | 41 | ) |
| 42 | self.client_headers = {} | ||
| 42 | 43 | ||
| 43 | async def close(self): | 44 | async def close(self): |
| 44 | await self.socket.close() | 45 | await self.socket.close() |
| 45 | 46 | ||
| 47 | async def handle_headers(self, headers): | ||
| 48 | return {} | ||
| 49 | |||
| 46 | async def process_requests(self): | 50 | async def process_requests(self): |
| 47 | try: | 51 | try: |
| 48 | self.logger.info("Client %r connected" % (self.socket.address,)) | 52 | self.logger.info("Client %r connected" % (self.socket.address,)) |
| @@ -64,12 +68,20 @@ class AsyncServerConnection(object): | |||
| 64 | ) | 68 | ) |
| 65 | return | 69 | return |
| 66 | 70 | ||
| 67 | # Read headers. Currently, no headers are implemented, so look for | 71 | # Read headers |
| 68 | # an empty line to signal the end of the headers | 72 | self.client_headers = {} |
| 69 | while True: | 73 | while True: |
| 70 | header = await self.socket.recv() | 74 | header = await self.socket.recv() |
| 71 | if not header: | 75 | if not header: |
| 76 | # Empty line. End of headers | ||
| 72 | break | 77 | break |
| 78 | tag, value = header.split(":", 1) | ||
| 79 | self.client_headers[tag.lower()] = value.strip() | ||
| 80 | |||
| 81 | if self.client_headers.get("needs-headers", "false") == "true": | ||
| 82 | for k, v in (await self.handle_headers(self.client_headers)).items(): | ||
| 83 | await self.socket.send("%s: %s" % (k, v)) | ||
| 84 | await self.socket.send("") | ||
| 73 | 85 | ||
| 74 | # Handle messages | 86 | # Handle messages |
| 75 | while True: | 87 | while True: |
