Comparison

net/http/files.lua @ 13868:14b52f217f7a 13.0

net.http.files: Fix #1927 Problem was type confusion where the `data` variable was expected to be a string later but ended up being the table stored in the cache. Here a different variable is used for the cache entry and the data.
author Kim Alvefur <zash@zash.se>
date Fri, 25 Apr 2025 17:05:13 +0200 (2 months ago)
parent 13446:dba7073f1452
comparison
equal deleted inserted replaced
13867:eabd38507c1d 13868:14b52f217f7a
88 if etag == if_none_match 88 if etag == if_none_match
89 or (not if_none_match and last_modified == if_modified_since) then 89 or (not if_none_match and last_modified == if_modified_since) then
90 return 304; 90 return 304;
91 end 91 end
92 92
93 local data = cache:get(orig_path); 93 local data;
94 if data and data.etag == etag then 94 local cached = cache:get(orig_path);
95 response_headers.content_type = data.content_type; 95 if cached and cached.etag == etag then
96 data = data.data; 96 response_headers.content_type = cached.content_type;
97 cache:set(orig_path, data); 97 data = cached.data;
98 cache:set(orig_path, cached);
98 elseif attr.mode == "directory" and path then 99 elseif attr.mode == "directory" and path then
99 if full_path:sub(-1) ~= "/" then 100 if full_path:sub(-1) ~= "/" then
100 local dir_path = { is_absolute = true, is_directory = true }; 101 local dir_path = { is_absolute = true, is_directory = true };
101 for dir in orig_path:gmatch("[^/]+") do dir_path[#dir_path+1]=dir; end 102 for dir in orig_path:gmatch("[^/]+") do dir_path[#dir_path+1]=dir; end
102 response_headers.location = build_path(dir_path); 103 response_headers.location = build_path(dir_path);