Skip to content

Conversation

@wryun
Copy link

@wryun wryun commented Nov 19, 2024

This allows us to set 'Cache-Control: no-cache', which makes it possible to develop LuCI JS without resorting to disabling the cache in the browser dev tools.

See: openwrt/luci#7059

If this was merged, the follow up to OpenWrt would look something like:

diff --git a/package/network/services/uhttpd/files/uhttpd.init b/package/network/services/uhttpd/files/uhttpd.init
index 89ca0c6c1d..3589024bbd 100755
--- a/package/network/services/uhttpd/files/uhttpd.init
+++ b/package/network/services/uhttpd/files/uhttpd.init
@@ -103,6 +103,10 @@ append_ucode_prefix() {
        fi
 }
 
+append_extra_header() {
+       procd_append_param command -z "$1"
+}
+
 start_instance()
 {
        UHTTPD_CERT=""
@@ -190,6 +194,8 @@ start_instance()
                procd_append_param command -I "$path"
        done
 
+       config_list_foreach "$cfg" extra_header append_extra_header
+
        config_get https "$cfg" listen_https
        config_get UHTTPD_KEY  "$cfg" key  /etc/uhttpd.key
        config_get UHTTPD_CERT "$cfg" cert /etc/uhttpd.crt

main.c Outdated
fprintf(stderr, "Error: invalid extra header (-z) - missing colon\n");
exit(1);
}
extra_header->header = strdup(optarg);
Copy link

@stokito stokito Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may use the optarg without duplication, see the alias parsing above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks, though it scare me a little :)

}
if (strchr(optarg, ':') == NULL) {
fprintf(stderr, "Error: invalid extra header (-z) - missing colon\n");
exit(1);
Copy link

@stokito stokito Nov 19, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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).

Copy link

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link

@stokito stokito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

This allows us to set 'Cache-Control: no-cache', which makes it
possible to develop LuCI JS without resorting to disabling the cache
in the browser dev tools.

Signed-off-by: James Haggerty <james.haggerty@morsemicro.com>
@wryun wryun force-pushed the allow-adding-additional-headers branch from 938187b to 1bdaac0 Compare November 19, 2024 23:37
morse-arienjudge pushed a commit to MorseMicro/openwrt that referenced this pull request Mar 3, 2025
This allows us to set something like:

	list extra_header 'Cache-Control: no-cache'

And no longer run into issues with caching JS files during development.
The intent would be to make the sync.py script automatically check/set
this.

See:

openwrt/luci#7059

and

openwrt/uhttpd#13


Approved-by: Evan Benn
Approved-by: Lyall Beveridge
@Neustradamus
Copy link

@wryun: What is the situation of your PR?

@wryun
Copy link
Author

wryun commented Jul 14, 2025

@Neustradamus can you explain what you mean by 'the situation of your PR'? I'm just hoping someone merges it; I have no permissions on this (or any) OpenWrt repository.

@Neustradamus
Copy link

@wryun: It is ready to be merged?
OpenWrt team, @stokito can look it?

" -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"
Copy link

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 z to H with long opt --header. Similar to curl but also similarly to npm http-server, to thecoshman/http and miniserve

Copy link
Author

@wryun wryun Jul 21, 2025

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.

@stokito
Copy link

stokito commented Jul 14, 2025

I don't have merge right and all my path(es?) to the uhttpd waiting years to be reviewed.

The uhttpd started as a replacement for the BusyBox httpd (here it contains the -m option) but now it has so many features that makes it too heavy for small routers (with 4mb space) but for larger routers it simply better to use the Lighttpd. Some options I would better to remove.
I'm not against the feature, just want to clarify why would we need it:

  1. Specify cache header. The uhttpd has cache validation with ETag so this is not really important.
  2. CORS headers: this anyway won't help, the CORS headers are stupidly designed and they'll need for some code to set the Access-Control-Allow-Origin: example.com with the explicit domain from Origin. That's why the mini servers have a separate option to enable CORS: the [npm http-server] has --cors option, dufs has --enable-cors, serverino maybe some others.
  3. Content-Security-Policy (CSP) header may be useful but it usually can't be made generic for all pages, it should be specified by the Web App itself but this means to use something like .htaccess with all it's downsides.
    Maybe I missed something. Generally if the feature wasn't requested for decades then it probably is not needed so often.

@wryun
Copy link
Author

wryun commented Jul 21, 2025

@stokito as identified in the original issue, the behaviour of browser caching without a Cache-Control header is based on heuristics. What this means is that they don't always check the ETag, but sometimes present a cached file if they think the resource has not changed for some time.

When making JS changes this is frustrating, as it means you need to have all caching disabled and the debug tools open for reliable behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants