在 varnish 中取消授权 header,但也会将 header 发送到后端

unset Authorization header in varnish but also send the header to backend

我想删除 varnish vcl 中的授权 header,但还需要将此 header 发送到 back-end。

sub vcl_recv {
    unset req.http.Authorization;
}

这看起来像是个坏主意,但使用一些基本的 VCL 绝对可行。例如:

sub vcl_recv {
    if (req.http.Authorization) {
        set req.http.Authorization-Copy = req.http.Authorization;
        unset req.http.Authorization;
    } else {
        unset set req.http.Authorization-Copy;
    }
}

sub vcl_backend_fetch {
    if (bereq.http.Authorization-Copy) {
        set bereq.http.Authorization = bereq.http.Authorization-Copy;
        unset bereq.http.Authorization-Copy;
    }
}