nghttpd: Don't show read error if mime types file is not set by user manually
This commit is contained in:
parent
41002a77d4
commit
1e7f0d833e
|
@ -183,6 +183,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
Config config;
|
||||
bool color = false;
|
||||
auto mime_types_file_set_manually = false;
|
||||
|
||||
while (1) {
|
||||
static int flag = 0;
|
||||
static option long_options[] = {
|
||||
|
@ -335,6 +337,7 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
case 9:
|
||||
// mime-types-file option
|
||||
mime_types_file_set_manually = true;
|
||||
config.mime_types_file = optarg;
|
||||
break;
|
||||
}
|
||||
|
@ -375,7 +378,13 @@ int main(int argc, char **argv) {
|
|||
config.htdocs = "./";
|
||||
}
|
||||
|
||||
config.mime_types = util::read_mime_types(config.mime_types_file.c_str());
|
||||
if (util::read_mime_types(config.mime_types,
|
||||
config.mime_types_file.c_str()) != 0) {
|
||||
if (mime_types_file_set_manually) {
|
||||
std::cerr << "--mime-types-file: Could not open mime types file: "
|
||||
<< config.mime_types_file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
set_color_output(color || isatty(fileno(stdout)));
|
||||
|
||||
|
|
10
src/util.cc
10
src/util.cc
|
@ -1218,13 +1218,11 @@ uint64_t get_uint64(const uint8_t *data) {
|
|||
return n;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> read_mime_types(const char *filename) {
|
||||
std::map<std::string, std::string> res;
|
||||
|
||||
int read_mime_types(std::map<std::string, std::string> &res,
|
||||
const char *filename) {
|
||||
std::ifstream infile(filename);
|
||||
if (!infile) {
|
||||
std::cerr << "Could not open mime types file: " << filename << std::endl;
|
||||
return res;
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto delim_pred = [](char c) { return c == ' ' || c == '\t'; };
|
||||
|
@ -1252,7 +1250,7 @@ std::map<std::string, std::string> read_mime_types(const char *filename) {
|
|||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
|
|
@ -707,7 +707,11 @@ uint32_t get_uint32(const uint8_t *data);
|
|||
// order and returns it in host byte order.
|
||||
uint64_t get_uint64(const uint8_t *data);
|
||||
|
||||
std::map<std::string, std::string> read_mime_types(const char *filename);
|
||||
// Reads mime types file (see /etc/mime.types), and stores extension
|
||||
// -> MIME type map in |res|. This function returns 0 if it succeeds,
|
||||
// or -1.
|
||||
int read_mime_types(std::map<std::string, std::string> &res,
|
||||
const char *filename);
|
||||
|
||||
} // namespace util
|
||||
|
||||
|
|
Loading…
Reference in New Issue