From f3a8927a509e08db63d7cd62ddca4909b5a2b47b Mon Sep 17 00:00:00 2001 From: Bryan Kok Date: Sun, 18 Aug 2019 14:54:52 +0800 Subject: [PATCH] Document web.FileResponse --- CHANGES/3958.doc | 1 + docs/web_reference.rst | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 CHANGES/3958.doc diff --git a/CHANGES/3958.doc b/CHANGES/3958.doc new file mode 100644 index 00000000000..41cc5697d6c --- /dev/null +++ b/CHANGES/3958.doc @@ -0,0 +1 @@ +Add documentation for ``aiohttp.web.FileResponse``. \ No newline at end of file diff --git a/docs/web_reference.rst b/docs/web_reference.rst index d6783ffc368..5df154104d7 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -850,6 +850,33 @@ Response *Content-Length* HTTP header. +FileResponse +^^^^^^^^^^^^^^ + +.. class:: FileResponse(*, path, chunk_size=256*1024, status=200, reason=None, headers=None) + + The response class used to send files, inherited from :class:`StreamResponse`. + + Supports the ``Content-Range`` and ``If-Range`` HTTP Headers in requests. + + The actual :attr:`body` sending happens in overridden :meth:`~StreamResponse.prepare`. + + :param path: Path to file. Accepts both :class:`str` and :class:`pathlib.Path`. + :param int chunk_size: Chunk size in bytes which will be passed into + :meth:`io.RawIOBase.read` in the event that the + ``sendfile`` system call is not supported. + + :param int status: HTTP status code, ``200`` by default. + + :param str reason: HTTP reason. If param is ``None`` reason will be + calculated basing on *status* + parameter. Otherwise pass :class:`str` with + arbitrary *status* explanation.. + + :param collections.abc.Mapping headers: HTTP headers that should be added to + response's ones. The ``Content-Type`` response header + will be overridden if provided. + WebSocketResponse ^^^^^^^^^^^^^^^^^