From 0a4fa559e44ed3e77f723092feab977539b8aab0 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 1 Sep 2026 07:54:16 +0200 Subject: Address PR review: pass raw socket to headers callback, use ok/err return convention Rename response_headers to headers_callback, pass the raw connection as a 4th argument (for use cases like WebSocket upgrade handoff), and switch its return contract to the idiomatic ok/err shape used elsewhere in this file: truthy ok continues (optionally swapping in a new sink), falsy ok closes the connection and propagates the callback's error via socket.protect instead of faking a success return. Claude-Session: https://claude.ai/code/session_01S4imKCU4hxDg96DXj9hxSB --- src/http.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/http.lua') diff --git a/src/http.lua b/src/http.lua index 6cdc90a..3e2c789 100644 --- a/src/http.lua +++ b/src/http.lua @@ -360,7 +360,7 @@ local trequest, tredirect headers = reqt.headers, proxy = reqt.proxy, maxredirects = reqt.maxredirects, - response_headers = reqt.response_headers, + headers_callback = reqt.headers_callback, nredirects = (reqt.nredirects or 0) + 1, create = reqt.create } @@ -405,12 +405,8 @@ end end -- here we are finally done -- provide an opportunity to abort or replace the sink based on the response headers - if nreqt.response_headers then - local abort, sink = nreqt.response_headers(code, headers, status) - if abort then - h:close() - return 1, code, headers, status - end + if nreqt.headers_callback then + local _, sink = h.try(nreqt.headers_callback(code, headers, status, h.c)) if sink then nreqt.sink = sink end -- cgit v1.2.3-55-g6feb