Changeset

11527:eaff6e548f12

net.http.server: Split out method for sending only the header Makes it easier to reuse, e.g. for SSE or websockets or other custom responses.
author Kim Alvefur <zash@zash.se>
date Sat, 24 Apr 2021 10:50:24 +0200
parents 11526:15a3db955ad3
children 11528:d3b0049e50f5
files net/http/server.lua
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/net/http/server.lua	Wed Apr 21 17:11:58 2021 +0200
+++ b/net/http/server.lua	Sat Apr 24 10:50:24 2021 +0200
@@ -256,6 +256,7 @@
 		persistent = persistent;
 		conn = conn;
 		send = _M.send_response;
+		write_headers = _M.write_headers;
 		send_file = _M.send_file;
 		done = _M.finish_response;
 		finish_cb = finish_cb;
@@ -329,10 +330,14 @@
 	return output;
 end
 _M.prepare_header = prepare_header;
-function _M.send_head_response(response)
+function _M.write_headers(response)
 	if response.finished then return; end
 	local output = prepare_header(response);
 	response.conn:write(t_concat(output));
+end
+function _M.send_head_response(response)
+	if response.finished then return; end
+	_M.write_headers(response);
 	response:done();
 end
 function _M.send_response(response, body)
@@ -381,7 +386,7 @@
 			return response:done();
 		end
 	end
-	response.conn:write(t_concat(prepare_header(response)));
+	_M.write_headers(response);
 	return true;
 end
 function _M.finish_response(response)