Proof not showing up (#1028)

* fix proof header

* fix set directive

* var mismatch

* var mismatch

* add comments
This commit is contained in:
Karol Wypchło 2021-08-02 16:48:04 +02:00 committed by GitHub
parent c7a34dbfdb
commit 30da6c4699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -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 {