1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

add HTTP server support with given document root.

This commit is contained in:
Falk Werner 2023-02-04 19:59:52 +01:00
parent a24dfd0fb5
commit 7783b294cc
5 changed files with 31 additions and 7 deletions

View File

@ -17,9 +17,12 @@ filesystem via fuse and exposes it's API via websockets.
| --wf-key | path | - | Optional. Specify the file path of the server's private key |
| --wf-authenticator | path | - | Optional. Specify the file path of the authenticator executable |
| --wf-auth-header | name | - | Optional. Specify the name of the HTTP header used for authentication |
| --wf-docroot | path | - | Optional. Enabled HTTP server with given document root. |
| --wf-timeout | timeout | 10 | Optional. Specify the communication timeout. |
| --wf-version | - | - | Print version and exit. |
**Note:** All paths must be absolute _(this might be relaxed if future versions)_.
## Fuse options
| Option | Descripion |

View File

@ -40,6 +40,7 @@ WEBFUSE options:
--wf-key PATH path of the server's private key (optional)
--wf-authenticator PATH path of authenticatior app (optional)
--wf-auth-header NAME name of the authentication header (optional)
--wf-docroot PATH enables HTTP server with given document root (optional)
--wf-timeout TIMEOUT communication timeout in seconds (default: 10)
--wf-version print version and exit
)";

View File

@ -112,6 +112,10 @@ ws_config::ws_config(int argc, char * argv[])
timeout_secs = static_cast<uint64_t>(std::stoi(timeout_str));
}
}
else if (arg == "--wf-docroot")
{
get_arg(*this, reader, docroot, "missing DOCROOT");
}
else if (arg == "--wf-version")
{
cmd = command::print_version;

View File

@ -27,6 +27,7 @@ public:
uint16_t port;
std::string vhost_name;
std::string docroot;
bool use_tls;
std::string cert_path;

View File

@ -71,20 +71,33 @@ class ws_server::detail
public:
detail(ws_config const & config)
: shutdown_requested(false)
, docroot(config.docroot)
, data(config.authenticator, config.auth_header)
, timeout_secs(config.timeout_secs)
{
lws_set_log_level(0, nullptr);
memset(reinterpret_cast<void*>(&http_mount), 0, sizeof(http_mount));
http_mount.mount_next = nullptr;
http_mount.mountpoint = "/";
http_mount.origin = docroot.c_str();
http_mount.def = "index.html";
http_mount.origin_protocol = LWSMPRO_FILE;
http_mount.mountpoint_len = 1;
memset(reinterpret_cast<void*>(protocols), 0, sizeof(protocols));
protocols[0].name = "webfuse2";
protocols[0].callback = &ws_server_callback;
protocols[0].per_session_data_size = 0;
protocols[0].user = reinterpret_cast<void*>(&data);
protocols[0].name = "http";
protocols[0].callback = lws_callback_http_dummy;
protocols[1].name = "webfuse2";
protocols[1].callback = &ws_server_callback;
protocols[1].per_session_data_size = 0;
protocols[1].user = reinterpret_cast<void*>(&data);
memset(reinterpret_cast<void*>(&info), 0, sizeof(info));
info.port = config.port;
info.protocols = protocols;
info.mounts = &http_mount;
info.protocols = (docroot.empty()) ? &protocols[1] : protocols;
info.vhost_name = config.vhost_name.c_str();
info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE | LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
@ -121,9 +134,11 @@ public:
std::thread thread;
std::atomic<bool> shutdown_requested;
lws_protocols protocols[2];
lws_protocols protocols[3];
lws_http_mount http_mount;
lws_context_creation_info info;
lws_context * context;
std::string docroot;
server_handler data;
uint64_t timeout_secs;
};