For those who embed CivetWeb into their application, CivetWeb offers a feature "file in memory" (users of the pre-built binaries can stop reading here - they are not affected).
You can pass a callback "open_file" to "mg_start", to tell CivetWeb not to read a file from the disk, but take the data from some memory buffer prepared by the embedding application.
/* Called when civetweb tries to open a file. Used to intercept file open
calls, and serve file data from memory instead.
Parameters:
path: Full path to the file to open.
data_len: Placeholder for the file size, if file is served from
memory.
Return value:
NULL: do not serve file from memory, proceed with normal file open.
non-NULL: pointer to the file contents in memory. data_len must be
initialized with the size of the memory block. */
const char *(*open_file)(const struct mg_connection *,
const char *path,
size_t *data_len);
Does anyone use this feature?
How are you using it?
From my point of view, this feature is superseded by the "
mg_add_request_handler
" function added by Thomas in CivetWeb 1.4 (September 2013). Instead of writing a callback returning a pointer for every known path, you call mg_add_request_handler for every known path and call mg_write there. Furthermore, the "file in memory" feature cannot know when the returned memory buffer is in use, and when it can be freed (except after the server exits), so *safely* it can only be used for const data. The handler callback can deliver different data for different users, different calls, ...
The original "file in memory" feature still exists for compatibility reasons, but I don't see any added value.
- keep it as it is (don't extend, don't drop, just like the last years)
- drop this feature to simplify the code, and make it slightly smaller and easier to maintain (keep it as "legacy interface" with a proper define for a version or two, provide a "how to replace" instruction and finally delete it
- extend this feature in some way to add value, for example by allowing to read and write .htpasswd files - but I think this is nothing a ram-disk would not do as well
- any other ideas?