mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-27 08:02:47 +03:00
58 lines
2.5 KiB
C
58 lines
2.5 KiB
C
/*
|
|
* Copyright (c) 2016 Lammert Bies
|
|
* Copyright (c) 2013-2016 the Civetweb developers
|
|
* Copyright (c) 2004-2013 Sergey Lyubka
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
|
|
|
|
#include "libhttp-private.h"
|
|
|
|
|
|
int XX_httplib_send_static_cache_header(struct mg_connection *conn) {
|
|
|
|
#if !defined(NO_CACHING)
|
|
/* Read the server config to check how long a file may be cached.
|
|
* The configuration is in seconds. */
|
|
int max_age = atoi(conn->ctx->config[STATIC_FILE_MAX_AGE]);
|
|
if (max_age <= 0) {
|
|
/* 0 means "do not cache". All values <0 are reserved
|
|
* and may be used differently in the future. */
|
|
/* If a file should not be cached, do not only send
|
|
* max-age=0, but also pragmas and Expires headers. */
|
|
return XX_httplib_send_no_cache_header(conn);
|
|
}
|
|
|
|
/* Use "Cache-Control: max-age" instead of "Expires" header.
|
|
* Reason: see https://www.mnot.net/blog/2007/05/15/expires_max-age */
|
|
/* See also https://www.mnot.net/cache_docs/ */
|
|
/* According to RFC 2616, Section 14.21, caching times should not exceed
|
|
* one year. A year with 365 days corresponds to 31536000 seconds, a leap
|
|
* year to 31622400 seconds. For the moment, we just send whatever has
|
|
* been configured, still the behavior for >1 year should be considered
|
|
* as undefined. */
|
|
return mg_printf(conn, "Cache-Control: max-age=%u\r\n", (unsigned)max_age);
|
|
#else /* NO_CACHING */
|
|
return XX_httplib_send_no_cache_header(conn);
|
|
#endif /* !NO_CACHING */
|
|
|
|
} /* XX_httplib_send_static_cache_header */
|