@@ -75,13 +75,28 @@ sub vcl_recv {
7575 # Change our backend to S3 to look for the file there, re-enable clustering and continue
7676 # https://www.slideshare.net/Fastly/advanced-vcl-how-to-use-restart
7777 if (req.restarts > 0 && req.url ~ "^/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/" ) {
78- set req.backend = F_S3 ;
78+ set req.backend = F_GCS ;
7979 set req.http.Fastly-Force-Shield = "1" ;
8080 }
8181
82- # Requests that are for an *actual* file get disaptched to Amazon S3 instead of
83- # to our typical backends. We need to setup the request to correctly access
84- # S3 and to authorize ourselves to S3.
82+ # Requests that are for an *actual* file get disaptched to object storage instead of
83+ # to our typical backends.
84+
85+ # If our file request is being dispatched to B2, we need to setup the request to correctly
86+ # access B2 and to authorize ourselves to B2 with S3 compatible auth.
87+ if (req.backend == F_B2 && req.url ~ "^/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/" ) {
88+ # Setup our environment to better match what S3 expects/needs
89+ set req.http.Host = var.B2-Bucket-Name "s3.us-east-005.backblazeb2.com" ;
90+ set req.http.Date = now ;
91+ set req.url = regsuball (req.url , "\+ " , urlencode ("+" ));
92+
93+ # Compute the Authorization header that B2 requires to be able to
94+ # access the files stored there.
95+ set req.http.Authorization = "AWS " var.B2-Application-Key-ID ":" digest.hmac_sha1_base64 (var.B2-Application-Key , "GET" LF LF LF req.http.Date LF "/" var.S3-Bucket-Name req.url.path );
96+ }
97+
98+ # If our file request is being dispatched to S3, we need to setup the request to correctly
99+ # access S3 and to authorize ourselves to S3.
85100 if (req.backend == F_S3 && req.url ~ "^/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/" ) {
86101 # Setup our environment to better match what S3 expects/needs
87102 set req.http.Host = var.S3-Bucket-Name ".s3.amazonaws.com" ;
@@ -92,6 +107,7 @@ sub vcl_recv {
92107 # access the files stored there.
93108 set req.http.Authorization = "AWS " var.AWS-Access-Key-ID ":" digest.hmac_sha1_base64 (var.AWS-Secret-Access-Key , "GET" LF LF LF req.http.Date LF "/" var.S3-Bucket-Name req.url.path );
94109 }
110+
95111 # If our file request is being dispatched to GCS, setup the request to correctly
96112 # access GCS and authorize ourselves with GCS interoperability credentials.
97113 if (req.backend == GCS && req.url ~ "^/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/" ) {
@@ -126,9 +142,9 @@ sub vcl_fetch {
126142 set beresp.cacheable = true ;
127143 }
128144
129- # If we successfully got a 404 response from GCS for a Package URL restart
130- # to check S3 for the file!
131- if (req.restarts == 0 && req.backend == GCS && req.url ~ "^/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/" && http_status_matches (beresp.status , "404" )) {
145+ # If we successfully got a 404 response from B2 for a Package URL restart
146+ # to check GCS for the file!
147+ if (req.restarts == 0 && req.backend == B2 && req.url ~ "^/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/" && http_status_matches (beresp.status , "404" )) {
132148 restart ;
133149 }
134150
0 commit comments