From 3581b58b9d5c09e3e37b7e20b41205ee3553aaa4 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Mon, 3 Aug 2026 22:48:50 +0200 Subject: Add HTTP response headers callback to allow for early abort or different sink depending on response --- src/http.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/http.lua b/src/http.lua index 21d3078..6cdc90a 100644 --- a/src/http.lua +++ b/src/http.lua @@ -360,6 +360,7 @@ local trequest, tredirect headers = reqt.headers, proxy = reqt.proxy, maxredirects = reqt.maxredirects, + response_headers = reqt.response_headers, nredirects = (reqt.nredirects or 0) + 1, create = reqt.create } @@ -403,6 +404,17 @@ end return tredirect(reqt, headers.location) 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 sink then + nreqt.sink = sink + end + end if shouldreceivebody(nreqt, code) then h:receivebody(headers, nreqt.sink, nreqt.step) end -- cgit v1.2.3-55-g6feb