Comparison

plugins/mod_httpserver.lua @ 2773:591c8ae9ae09

mod_httpserver: Read files in binary mode; fixes issues with serving binary files.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 10 Dec 2009 16:27:17 +0500
parent 2772:18d83fd07db1
child 2774:55ec6991c1a8
comparison
equal deleted inserted replaced
2772:18d83fd07db1 2773:591c8ae9ae09
45 end 45 end
46 return path; 46 return path;
47 end 47 end
48 48
49 function serve_file(path) 49 function serve_file(path)
50 local f, err = open(http_base..path, "r"); 50 local f, err = open(http_base..path, "rb");
51 if not f then return response_404; end 51 if not f then return response_404; end
52 local data = f:read("*a"); 52 local data = f:read("*a");
53 f:close(); 53 f:close();
54 local ext = path:match("%.([^.]*)$"); 54 local ext = path:match("%.([^.]*)$");
55 local mime = mime_map[ext]; -- Content-Type should be nil when not known 55 local mime = mime_map[ext]; -- Content-Type should be nil when not known