Skip to content

Commit

Permalink
remove the need for #define CROW_MAIN.
Browse files Browse the repository at this point in the history
This is achieved using the conts type qualifier as it gives internal linkage.
fixes #273

Signed-off-by: Luca Schlecker <luca.schlecker@hotmail.com>
  • Loading branch information
luca-schlecker committed Nov 21, 2021
1 parent b1718be commit 5823a59
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 26 deletions.
6 changes: 3 additions & 3 deletions include/crow/http_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ namespace crow

response(std::string contentType, std::string body) : body(std::move(body))
{
set_header("Content-Type",mime_types[contentType]);
set_header("Content-Type", mime_types.at(contentType));
}

response(int code, std::string contentType, std::string body): code(code),body(std::move(body))
{
set_header("Content-Type",mime_types[contentType]);
set_header("Content-Type", mime_types.at(contentType));
}

response& operator = (const response& r) = delete;
Expand Down Expand Up @@ -221,7 +221,7 @@ namespace crow
this->add_header("Content-length", std::to_string(file_info.statbuf.st_size));

if (extension != ""){
mimeType = mime_types[extension];
mimeType = mime_types.at(extension);
if (mimeType != "")
this-> add_header("Content-Type", mimeType);
else
Expand Down
7 changes: 1 addition & 6 deletions include/crow/mime_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <string>

namespace crow {

#ifdef CROW_MAIN
std::unordered_map<std::string, std::string> mime_types {
const std::unordered_map<std::string, std::string> mime_types {
{"shtml", "text/html"},
{"htm", "text/html"},
{"html", "text/html"},
Expand Down Expand Up @@ -115,7 +113,4 @@ namespace crow {
{"wmv", "video/x-ms-wmv"},
{"avi", "video/x-msvideo"}
};
#else
extern std::unordered_map<std::string, std::string> mime_types;
#endif
}
7 changes: 2 additions & 5 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
namespace crow
{

#ifdef CROW_MAIN
uint16_t INVALID_BP_ID{0xFFFF};
#else
extern uint16_t INVALID_BP_ID;
#endif
constexpr const uint16_t INVALID_BP_ID{0xFFFF};

/// A base class for all rules.

/// Used to provide a common interface for code dealing with different types of rules.
Expand Down
7 changes: 1 addition & 6 deletions include/crow/version.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#pragma once

namespace crow {

#ifdef CROW_MAIN
char VERSION[] = "master";
#else
extern char VERSION[];
#endif
constexpr const char VERSION[] = "master";
}
7 changes: 1 addition & 6 deletions scripts/nginx_mime2cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def main():
"#include <string>",
"",
"namespace crow {",
"",
"#ifdef CROW_MAIN"
tabspace + "std::unordered_map<std::string, std::string> mime_types {"])
tabspace + "const std::unordered_map<std::string, std::string> mime_types {"])

with open(file_path, "r") as mtfile:
incomplete = ""
Expand All @@ -44,9 +42,6 @@ def main():
outLines[-1] = outLines[-1][:-1]
outLines.extend([
tabspace + "};",
"#else",
"extern std::unordered_map<std::string, std::string> mime_types;",
"#endif",
"}"
])

Expand Down

0 comments on commit 5823a59

Please sign in to comment.