bpo-29654 : Support If-Modified-Since HTTP header (browser cache) (#298)
Return 304 response if file was not modified.
diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst
index fb5c1df..ee1c37c 100644
--- a/Doc/library/http.server.rst
+++ b/Doc/library/http.server.rst
@@ -343,11 +343,13 @@
:func:`os.listdir` to scan the directory, and returns a ``404`` error
response if the :func:`~os.listdir` fails.
- If the request was mapped to a file, it is opened and the contents are
- returned. Any :exc:`OSError` exception in opening the requested file is
- mapped to a ``404``, ``'File not found'`` error. Otherwise, the content
+ If the request was mapped to a file, it is opened. Any :exc:`OSError`
+ exception in opening the requested file is mapped to a ``404``,
+ ``'File not found'`` error. If there was a ``'If-Modified-Since'``
+ header in the request, and the file was not modified after this time,
+ a ``304``, ``'Not Modified'`` response is sent. Otherwise, the content
type is guessed by calling the :meth:`guess_type` method, which in turn
- uses the *extensions_map* variable.
+ uses the *extensions_map* variable, and the file contents are returned.
A ``'Content-type:'`` header with the guessed content type is output,
followed by a ``'Content-Length:'`` header with the file's size and a
@@ -360,6 +362,8 @@
For example usage, see the implementation of the :func:`test` function
invocation in the :mod:`http.server` module.
+ .. versionchanged:: 3.7
+ Support of the ``'If-Modified-Since'`` header.
The :class:`SimpleHTTPRequestHandler` class can be used in the following
manner in order to create a very basic webserver serving files relative to