async def send(self, request: Request) -> Response: 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.request = request self._pending_task = True if request_has_body(request) and request.expect_100_continue(): # don't send the body immediately; instead, wait for HTTP 100 # Continue interim response from server self.expect_100_continue = True self.transport.write(write_request_without_body(request)) return await self._wait_response() if is_small_request(request): self.transport.write(write_small_request(request)) else: response = await self._write_chunks(request, write_request) if response is not None: # this happens if the server sent a response before we completed # sending a body return response return await self._wait_response()
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()