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;
|
Config config;
|
||||||
bool color = false;
|
bool color = false;
|
||||||
|
auto mime_types_file_set_manually = false;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
static int flag = 0;
|
static int flag = 0;
|
||||||
static option long_options[] = {
|
static option long_options[] = {
|
||||||
|
@ -335,6 +337,7 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
// mime-types-file option
|
// mime-types-file option
|
||||||
|
mime_types_file_set_manually = true;
|
||||||
config.mime_types_file = optarg;
|
config.mime_types_file = optarg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +378,13 @@ int main(int argc, char **argv) {
|
||||||
config.htdocs = "./";
|
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)));
|
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;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::string> read_mime_types(const char *filename) {
|
int read_mime_types(std::map<std::string, std::string> &res,
|
||||||
std::map<std::string, std::string> res;
|
const char *filename) {
|
||||||
|
|
||||||
std::ifstream infile(filename);
|
std::ifstream infile(filename);
|
||||||
if (!infile) {
|
if (!infile) {
|
||||||
std::cerr << "Could not open mime types file: " << filename << std::endl;
|
return -1;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto delim_pred = [](char c) { return c == ' ' || c == '\t'; };
|
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
|
} // namespace util
|
||||||
|
|
|
@ -707,7 +707,11 @@ uint32_t get_uint32(const uint8_t *data);
|
||||||
// order and returns it in host byte order.
|
// order and returns it in host byte order.
|
||||||
uint64_t get_uint64(const uint8_t *data);
|
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
|
} // namespace util
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue