diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index db819e70..1678a257 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -426,6 +426,10 @@ server { set $skylink_v1 $skylink; set $skylink_v2 $skylink; + # variable for Skynet-Proof header that we need to inject + # into a response if the request was for skylink v2 + set $skynet_proof ''; + access_by_lua_block { -- detect whether requested skylink is v2 local isBase32v2 = string.len(ngx.var.skylink) == 55 and string.sub(ngx.var.skylink, 0, 2) == "04" @@ -437,6 +441,7 @@ server { local json = require('cjson') local resolve = json.decode(res.body) ngx.var.skylink_v1 = resolve.skylink + ngx.var.skynet_proof = res.header["Skynet-Proof"] end end @@ -451,10 +456,20 @@ server { end } + header_filter_by_lua_block { + -- not empty skynet_proof means this is a skylink v2 request + -- so we should replace the Skynet-Proof header with the one + -- we got from /skynet/resolve/ endpoint, otherwise we would + -- be serving cached empty v1 skylink Skynet-Proof header + if ngx.var.skynet_proof then + ngx.header["Skynet-Proof"] = ngx.var.skynet_proof + end + } + proxy_read_timeout 600; proxy_set_header User-Agent: Sia-Agent; - proxy_pass http://siad/skynet/skylink/$skylink$path$is_args$args; + proxy_pass http://siad/skynet/skylink/$skylink_v1$path$is_args$args; } location @dnslink_lookup {