break;
case 'call':
- http.write(render(() => {
+ http.write_headers();
+ http.output(render(() => {
runtime.call(action.module, action.function,
...(action.parameters ?? []),
...resolved.ctx.request_args
assert(type(mod[action.function]) == 'function',
`Module '${action.module}' does not export function '${action.function}'`);
- http.write(render(() => {
+ http.write_headers();
+ http.output(render(() => {
call(mod[action.function], mod, runtime.env,
...(action.parameters ?? []),
...resolved.ctx.request_args
break;
case 'cbi':
- http.write(render(() => {
+ http.write_headers();
+ http.output(render(() => {
runtime.call('luci.dispatcher', 'invoke_cbi_action',
action.path, null,
...resolved.ctx.request_args
break;
case 'form':
- http.write(render(() => {
+ http.write_headers();
+ http.output(render(() => {
runtime.call('luci.dispatcher', 'invoke_form_action',
action.path,
...resolved.ctx.request_args
let bridge = this.env.dispatcher.load_luabridge(optional);
if (bridge) {
+ let http = this.env.http;
+
this.L = bridge.create();
- this.L.set('L', proto({ write: print }, this.env));
+ this.L.set('L', proto({ write: (...args) => http.closed || print(...args) }, this.env));
this.L.invoke('require', 'luci.ucodebridge');
this.env.lua_active = true;
render_ucode: function(path, scope) {
let tmplfunc = loadfile(path, { raw_mode: false });
- call(tmplfunc, null, scope ?? {});
+
+ if (this.env.http.closed)
+ render(call, tmplfunc, null, scope ?? {});
+ else
+ call(tmplfunc, null, scope ?? {});
},
render_lua: function(path, scope) {