override_fetch
override_fetch(request, ctx) completely replaces SpyWeb’s internal HTTP client. Use this when you need custom fetching, like launching a Chrome instance via CDP or using a proxy rotater.
Signature
Section titled “Signature”function override_fetch(request, ctx) -> tableParameters
Section titled “Parameters”Same as before_fetch.
Returns
Section titled “Returns”| Return | Effect |
|---|---|
response object |
A standard response table ({ status = 200, body = "...", url = "..." }). Output acts exactly like a native fetch result and will still pass through after_fetch if defined. |
{ error = "msg" } |
Simulate a network failure |
nil or false |
Causes a pipeline error (“must return a response table”). Unlike other hooks, nil/false does NOT mean skip — this hook must always return a response table or an error table. |
Example
Section titled “Example”function override_fetch(request, ctx) local res, err = http_get("http://my-renderer.local/?url=" .. request.url) if not res then return { error = "renderer request failed: " .. err.error } end return { status = res.status, url = request.url, body = res.body, headers = res.headers }endSee Also
Section titled “See Also”- before_fetch - Modify the request (but still use built-in fetch)
- after_fetch - Process the response after fetching