Add canonical_origin config option
This commit is contained in:
parent
42da969ac5
commit
6aeba6acb6
|
@ -16,6 +16,7 @@ liking. Here's a list of what they are:
|
|||
- `bind_host` (string): What address to bind to
|
||||
- `bind_port` (zero or positive integer): What port to bind to
|
||||
- `image_proxy_url` (string): URL to proxy images to (see https://pixiv.cat/reverseproxy.html), a trailing slash is not needed
|
||||
- `canonical_origin` (string or null): A fallback canonical origin if set, useful if you're, say, running Pixwhile behind Ngrok
|
||||
|
||||
Pixwhile is intended to be run behind a reverse proxy (e.g. Nginx), so you
|
||||
should set your reverse proxy to proxy requests to
|
||||
|
|
|
@ -17,4 +17,7 @@ void from_json(const nlohmann::json& j, Config& config) {
|
|||
throw std::invalid_argument("Invalid port to bind to: "s + std::to_string(config.bind_port));
|
||||
}
|
||||
config.image_proxy_url = j.at("image_proxy_url").get<std::string>();
|
||||
if (j.contains("canonical_origin") && j["canonical_origin"].is_string()) {
|
||||
config.canonical_origin = j["canonical_origin"].get<std::string>();
|
||||
}
|
||||
}
|
||||
|
|
1
config.h
1
config.h
|
@ -8,6 +8,7 @@ struct Config {
|
|||
std::string bind_host = "127.0.0.1";
|
||||
int bind_port = 8080;
|
||||
blankie::murl::Url image_proxy_url{"https://i.pixiv.cat"};
|
||||
std::optional<std::string> canonical_origin;
|
||||
};
|
||||
|
||||
Config load_config(const char* path);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"bind_host": "127.0.0.1",
|
||||
"bind_port": 8080,
|
||||
"image_proxy_url": "https://i.pixiv.cat"
|
||||
"image_proxy_url": "https://i.pixiv.cat",
|
||||
"canonical_origin": null
|
||||
}
|
||||
|
|
|
@ -79,6 +79,9 @@ std::string get_origin(const httplib::Request& req, const Config& config) {
|
|||
if (req.has_header("X-Canonical-Origin")) {
|
||||
return req.get_header_value("X-Canonical-Origin");
|
||||
}
|
||||
if (config.canonical_origin) {
|
||||
return *config.canonical_origin;
|
||||
}
|
||||
|
||||
std::string origin = "http://";
|
||||
if (req.has_header("Host")) {
|
||||
|
|
Loading…
Reference in New Issue