async def send(self, request): if not self.open: # NB: if the connection is closed here, it is always possible to try again with a new connection # instead, if it happens later; we cannot retry because we started sending a request raise ConnectionClosedError(True) self._pending_task = True if is_small_request(request): self.transport.write(write_small_request(request)) else: async for chunk in write_request(request): if self._can_release: # the server returned a response before we ended sending the request return await self._wait_response() if not self.open: raise ConnectionClosedError(False) if self.writing_paused: await self.writable.wait() self.transport.write(chunk) return await self._wait_response()
async def test_request_writing(url, method, headers, content, expected_result): request = Request(method, url, headers).with_content(content) data = b"" async for chunk in scribe.write_request(request): data += chunk assert data == expected_result