aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2026-09-01 07:54:16 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2026-09-01 07:54:16 +0200
commit0a4fa559e44ed3e77f723092feab977539b8aab0 (patch)
treeab5a94d816ae176f9f1319222b26cc1758a3c764 /src
parent3581b58b9d5c09e3e37b7e20b41205ee3553aaa4 (diff)
downloadluasocket-0a4fa559e44ed3e77f723092feab977539b8aab0.tar.gz
luasocket-0a4fa559e44ed3e77f723092feab977539b8aab0.tar.bz2
luasocket-0a4fa559e44ed3e77f723092feab977539b8aab0.zip
Address PR review: pass raw socket to headers callback, use ok/err return conventionhttp-headers-callback
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
Diffstat (limited to 'src')
-rw-r--r--src/http.lua10
1 files changed, 3 insertions, 7 deletions
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
360 headers = reqt.headers, 360 headers = reqt.headers,
361 proxy = reqt.proxy, 361 proxy = reqt.proxy,
362 maxredirects = reqt.maxredirects, 362 maxredirects = reqt.maxredirects,
363 response_headers = reqt.response_headers, 363 headers_callback = reqt.headers_callback,
364 nredirects = (reqt.nredirects or 0) + 1, 364 nredirects = (reqt.nredirects or 0) + 1,
365 create = reqt.create 365 create = reqt.create
366 } 366 }
@@ -405,12 +405,8 @@ end
405 end 405 end
406 -- here we are finally done 406 -- here we are finally done
407 -- provide an opportunity to abort or replace the sink based on the response headers 407 -- provide an opportunity to abort or replace the sink based on the response headers
408 if nreqt.response_headers then 408 if nreqt.headers_callback then
409 local abort, sink = nreqt.response_headers(code, headers, status) 409 local _, sink = h.try(nreqt.headers_callback(code, headers, status, h.c))
410 if abort then
411 h:close()
412 return 1, code, headers, status
413 end
414 if sink then 410 if sink then
415 nreqt.sink = sink 411 nreqt.sink = sink
416 end 412 end