Use new ucode zlib library (#1629)

This commit is contained in:
Tim Wilkinson 2024-10-14 09:47:18 -07:00 committed by GitHub
parent bd68cd18b9
commit 61eca9449c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 21 deletions

View File

@ -160,6 +160,7 @@ CONFIG_PACKAGE_ubi-utils=y
CONFIG_PACKAGE_ucode-mod-log=y
CONFIG_PACKAGE_ucode-mod-math=y
CONFIG_PACKAGE_ucode-mod-resolv=y
CONFIG_PACKAGE_ucode-mod-zlib=y
CONFIG_PACKAGE_uhttpd=y
CONFIG_PACKAGE_uhttpd-mod-ucode=y
CONFIG_PACKAGE_vtun=y

View File

@ -33,7 +33,7 @@
import * as hardware from "aredn.hardware";
export const debug = true;
export const debug = false;
export const application = "/app";
export let preload = true;

View File

@ -39,6 +39,7 @@ import * as math from "math";
import * as uci from "uci";
import * as ubus from "ubus";
import * as log from "log";
import * as zlib from "zlib";
import * as lucihttp from "lucihttp";
import * as configuration from "aredn.configuration";
import * as hardware from "aredn.hardware";
@ -575,31 +576,15 @@ global.handle_request = function(env)
res = `<div><b>ERROR: ${e.message}</b><div><pre>${e.stacktrace[0].context}</pre></div>`;
}
if (!response.override) {
let datafile = null;
let gzip = false;
if (env.HTTP_ACCEPT_ENCODING && index(env.HTTP_ACCEPT_ENCODING, "gzip") !== -1 && config.compress) {
const r = fs.open("/dev/urandom");
if (r) {
const rid = r.read(8);
r.close();
datafile = `/tmp/uhttpd.${hexenc(rid)}`;
const x = fs.open(datafile, "wx");
if (x) {
x.write(res);
x.close();
const z = fs.popen("exec /bin/gzip -c " + datafile);
res = z.read("all");
z.close();
fs.unlink(datafile);
}
else {
datafile = null;
}
}
gzip = true;
res = zlib.deflate(res, true);
}
response.headers["Content-Length"] = `${length(res)}`;
uhttpd.send(
`Status: ${response.statusCode} OK\r\n`,
(datafile ? `Content-Encoding: gzip\r\n` : ``),
(gzip ? `Content-Encoding: gzip\r\n` : ``),
join("", map(keys(response.headers), k => k + ": " + response.headers[k] + "\r\n")),
"\r\n",
res

13
patches/761-ucode-zlib.patch Executable file
View File

@ -0,0 +1,13 @@
--- a/package/utils/ucode/Makefile
+++ b/package/utils/ucode/Makefile
@@ -174,6 +174,10 @@
uloop, ULOOP_SUPPORT, +libubox, \
The uloop module allows ucode scripts to interact with OpenWrt uloop event loop implementation.))
+$(eval $(call UcodeModule, \
+ zlib, ZLIB_SUPPORT, +zlib, \
+ The zlib plugin implements compression.))
+
$(eval $(call BuildPackage,libucode))
$(eval $(call BuildPackage,ucode))

View File

@ -45,6 +45,7 @@
752-mikrotik-nand-revert.patch
753-ubiquiti-2ac.patch
760-uhttp-ucode.patch
761-ucode-zlib.patch
800-upgrade-compatibility.patch
801-mikrotik-lhg-variants.patch
802-gpio-typo.patch