[core] (const buffer *) from strftime_cache_get()
This commit is contained in:
parent
784a4355d4
commit
d7a6a7a263
|
@ -293,7 +293,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
time_t mtime; /* the key */
|
||||
buffer *str; /* a buffer for the string represenation */
|
||||
buffer str; /* buffer for the string represenation */
|
||||
} mtime_cache_type;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -117,25 +117,26 @@ int http_response_redirect_to_directory(server *srv, connection *con, int status
|
|||
return 0;
|
||||
}
|
||||
|
||||
buffer * strftime_cache_get(server *srv, time_t last_mod) {
|
||||
const buffer * strftime_cache_get(server *srv, time_t last_mod) {
|
||||
static int i;
|
||||
struct tm *tm;
|
||||
|
||||
mtime_cache_type * const mtime_cache = srv->mtime_cache;
|
||||
for (int j = 0; j < FILE_CACHE_MAX; ++j) {
|
||||
if (srv->mtime_cache[j].mtime == last_mod)
|
||||
return srv->mtime_cache[j].str; /* found cache-entry */
|
||||
if (mtime_cache[j].mtime == last_mod)
|
||||
return &mtime_cache[j].str; /* found cache-entry */
|
||||
}
|
||||
|
||||
if (++i == FILE_CACHE_MAX) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
srv->mtime_cache[i].mtime = last_mod;
|
||||
tm = gmtime(&(srv->mtime_cache[i].mtime));
|
||||
buffer_clear(srv->mtime_cache[i].str);
|
||||
buffer_append_strftime(srv->mtime_cache[i].str, "%a, %d %b %Y %H:%M:%S GMT", tm);
|
||||
mtime_cache[i].mtime = last_mod;
|
||||
buffer * const b = &mtime_cache[i].str;
|
||||
buffer_clear(b);
|
||||
buffer_append_strftime(b, "%a, %d %b %Y %H:%M:%S GMT",
|
||||
gmtime(&(mtime_cache[i].mtime)));
|
||||
|
||||
return srv->mtime_cache[i].str;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -805,7 +805,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
|
|||
size_t m;
|
||||
off_t max_fsize;
|
||||
stat_cache_entry *sce = NULL;
|
||||
buffer *mtime = NULL;
|
||||
const buffer *mtime = NULL;
|
||||
buffer *content_type;
|
||||
|
||||
if (con->mode != DIRECT || con->http_status) return HANDLER_GO_ON;
|
||||
|
|
|
@ -1228,7 +1228,7 @@ static int mod_ssi_handle_request(server *srv, connection *con, handler_ctx *p)
|
|||
|
||||
if (p->conf.conditional_requests) {
|
||||
/* Generate "ETag" & "Last-Modified" headers */
|
||||
buffer *mtime = NULL;
|
||||
const buffer *mtime = NULL;
|
||||
|
||||
/* use most recently modified include file for ETag and Last-Modified */
|
||||
if (st.st_mtime < include_file_last_mtime)
|
||||
|
|
|
@ -53,5 +53,5 @@ void http_response_backend_done (server *srv, connection *con);
|
|||
void http_response_backend_error (server *srv, connection *con);
|
||||
void http_response_upgrade_read_body_unknown(server *srv, connection *con);
|
||||
|
||||
buffer * strftime_cache_get(server *srv, time_t last_mod);
|
||||
const buffer * strftime_cache_get(server *srv, time_t last_mod);
|
||||
#endif
|
||||
|
|
|
@ -258,7 +258,6 @@ static server *server_init(void) {
|
|||
|
||||
for (int i = 0; i < FILE_CACHE_MAX; ++i) {
|
||||
srv->mtime_cache[i].mtime = (time_t)-1;
|
||||
srv->mtime_cache[i].str = buffer_init();
|
||||
}
|
||||
|
||||
li_rand_reseed();
|
||||
|
@ -298,7 +297,7 @@ static server *server_init(void) {
|
|||
__attribute_cold__
|
||||
static void server_free(server *srv) {
|
||||
for (int i = 0; i < FILE_CACHE_MAX; ++i) {
|
||||
buffer_free(srv->mtime_cache[i].str);
|
||||
free(srv->mtime_cache[i].str.ptr);
|
||||
}
|
||||
|
||||
if (oneshot_fd > 0) {
|
||||
|
|
Loading…
Reference in New Issue