-
Notifications
You must be signed in to change notification settings - Fork 12
main/file: add support for custom headers to file serving #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,7 @@ static int usage(const char *name) | |
| " -d string URL decode given string\n" | ||
| " -r string Specify basic auth realm\n" | ||
| " -m string MD5 crypt given string\n" | ||
| " -z string Add additional response header (can use multiple times)\n" | ||
| "\n", name | ||
| ); | ||
| return 1; | ||
|
|
@@ -193,6 +194,7 @@ static void init_defaults_pre(void) | |
| conf.cgi_path = "/sbin:/usr/sbin:/bin:/usr/bin"; | ||
| INIT_LIST_HEAD(&conf.cgi_alias); | ||
| INIT_LIST_HEAD(&conf.lua_prefix); | ||
| INIT_LIST_HEAD(&conf.extra_header); | ||
| #if HAVE_UCODE | ||
| INIT_LIST_HEAD(&conf.ucode_prefix); | ||
| #endif | ||
|
|
@@ -271,6 +273,7 @@ static void add_ucode_prefix(const char *prefix, const char *handler) { | |
| int main(int argc, char **argv) | ||
| { | ||
| struct alias *alias; | ||
| struct extra_header *extra_header; | ||
| bool nofork = false; | ||
| char *port; | ||
| int opt, ch; | ||
|
|
@@ -293,7 +296,7 @@ int main(int argc, char **argv) | |
| init_defaults_pre(); | ||
| signal(SIGPIPE, SIG_IGN); | ||
|
|
||
| while ((ch = getopt(argc, argv, "A:ab:C:c:Dd:E:e:fh:H:I:i:K:k:L:l:m:N:n:O:o:P:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) { | ||
| while ((ch = getopt(argc, argv, "A:ab:C:c:Dd:E:e:fh:H:I:i:K:k:L:l:m:N:n:O:o:P:p:qRr:Ss:T:t:U:u:Xx:y:z:")) != -1) { | ||
| switch(ch) { | ||
| #ifdef HAVE_TLS | ||
| case 'C': | ||
|
|
@@ -408,6 +411,20 @@ int main(int argc, char **argv) | |
| list_add(&alias->list, &conf.cgi_alias); | ||
| break; | ||
|
|
||
| case 'z': | ||
| extra_header = calloc(1, sizeof(*extra_header)); | ||
| if (!extra_header) { | ||
| fprintf(stderr, "Error: failed to allocate extra_header\n"); | ||
| exit(1); | ||
| } | ||
| if (strchr(optarg, ':') == NULL) { | ||
| fprintf(stderr, "Error: invalid extra header (-z) - missing colon\n"); | ||
| exit(1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather not exit the whole webserver and lost access to Luci if the header is ivalid. But it looks like everywhere else the same behavior.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, but I think if you're changing the webserver settings you should have the expectation you may mess it up and have an alternative access mechanism (i.e. ssh). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally yes, but here we in the embedded world. A user may lost an access to its router. In the same time if some header is not present and something was broken then it may be not so critical for a security.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you pointed out, though, the general behaviour of bad options in uhttpd is that the server will not load, even if they're non-critical (e.g. missing 404 handler)... I guess I'm reluctant to change this unless someone else chimes in and says that it's the thing that's blocking a merge. |
||
| } | ||
| extra_header->header = optarg; | ||
| list_add(&extra_header->list, &conf.extra_header); | ||
| break; | ||
|
|
||
| case 'i': | ||
| optarg = strdup(optarg); | ||
| port = strchr(optarg, '='); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to change the
ztoHwith long opt--header. Similar tocurlbut also similarly to npm http-server, to thecoshman/http and miniserveUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
H is, unfortunately, already used (see getopt). longopts are not supported.