@@ -15,6 +15,8 @@ This is implemented in the following steps:
15
15
2 . [ Configuring asset certification] ( #configuring-asset-certification )
16
16
3 . [ Inserting assets into the asset router] ( #inserting-assets-into-the-asset-router )
17
17
4 . [ Serving assets] ( #serving-assets )
18
+ 5 . [ Deleting assets] ( #deleting-assets )
19
+ 6 . [ Querying assets] ( #querying-assets )
18
20
19
21
For canisters that need it, it's also possible to [ delete assets] ( #deleting-assets ) .
20
22
@@ -167,6 +169,7 @@ on the `/index.html` path, in addition to serving as the fallback for the `/`
167
169
scope and setting ` / ` as an alias for this asset.
168
170
169
171
``` rust
172
+ use ic_http_certification :: StatusCode ;
170
173
use ic_asset_certification :: {AssetConfig , AssetFallbackConfig };
171
174
172
175
let config = AssetConfig :: File {
@@ -177,6 +180,7 @@ let config = AssetConfig::File {
177
180
],
178
181
fallback_for : vec! [AssetFallbackConfig {
179
182
scope : " /" . to_string (),
183
+ status_code : Some (StatusCode :: OK ),
180
184
}],
181
185
aliased_by : vec! [" /" . to_string ()],
182
186
encodings : vec! [
@@ -206,6 +210,7 @@ Multiple aliases are also configured for this asset, namely:
206
210
Requests to any of those aliases will serve the ` /404.html ` asset.
207
211
208
212
``` rust
213
+ use ic_http_certification :: StatusCode ;
209
214
use ic_asset_certification :: {AssetConfig , AssetFallbackConfig };
210
215
211
216
let config = AssetConfig :: File {
@@ -217,9 +222,11 @@ let config = AssetConfig::File {
217
222
fallback_for : vec! [
218
223
AssetFallbackConfig {
219
224
scope : " /css" . to_string (),
225
+ status_code : Some (StatusCode :: NOT_FOUND ),
220
226
},
221
227
AssetFallbackConfig {
222
228
scope : " /js" . to_string (),
229
+ status_code : Some (StatusCode :: NOT_FOUND ),
223
230
},
224
231
],
225
232
aliased_by : vec! [
@@ -269,6 +276,7 @@ For example, the following pattern will match all `.js` files in the `js`
269
276
directory:
270
277
271
278
``` rust
279
+ use ic_http_certification :: StatusCode ;
272
280
use ic_asset_certification :: AssetConfig ;
273
281
274
282
let config = AssetConfig :: Pattern {
@@ -331,6 +339,7 @@ the appropriate response.
331
339
Assets can be inserted using the ` certify_assets ` method:
332
340
333
341
``` rust
342
+ use ic_http_certification :: StatusCode ;
334
343
use ic_asset_certification :: {Asset , AssetConfig , AssetFallbackConfig , AssetRouter , AssetRedirectKind };
335
344
336
345
let mut asset_router = AssetRouter :: default ();
@@ -384,6 +393,7 @@ let asset_configs = vec![
384
393
)],
385
394
fallback_for : vec! [AssetFallbackConfig {
386
395
scope : " /" . to_string (),
396
+ status_code : Some (StatusCode :: OK ),
387
397
}],
388
398
aliased_by : vec! [" /" . to_string ()],
389
399
encodings : vec! [
@@ -460,7 +470,7 @@ This method will return a response, a witness and an expression path, which can
460
470
alongside the canister's data certificate to add the required certificate header to the response.
461
471
462
472
``` rust
463
- use ic_http_certification :: {HttpRequest , utils :: add_v2_certificate_header};
473
+ use ic_http_certification :: {HttpRequest , utils :: add_v2_certificate_header, StatusCode };
464
474
use ic_asset_certification :: {Asset , AssetConfig , AssetFallbackConfig , AssetRouter };
465
475
466
476
let mut asset_router = AssetRouter :: default ();
@@ -478,6 +488,7 @@ let asset_config = AssetConfig::File {
478
488
],
479
489
fallback_for : vec! [AssetFallbackConfig {
480
490
scope : " /" . to_string (),
491
+ status_code : Some (StatusCode :: OK ),
481
492
}],
482
493
aliased_by : vec! [" /" . to_string ()],
483
494
encodings : vec! [],
@@ -522,6 +533,7 @@ only includes Brotli, then the Gzip file will not be deleted.
522
533
Using the same base example used to demonstrate certifying assets:
523
534
524
535
``` rust
536
+ use ic_http_certification :: StatusCode ;
525
537
use ic_asset_certification :: {Asset , AssetConfig , AssetFallbackConfig , AssetRouter , AssetRedirectKind , AssetEncoding };
526
538
527
539
let mut asset_router = AssetRouter :: default ();
@@ -575,6 +587,7 @@ let asset_configs = vec![
575
587
)],
576
588
fallback_for : vec! [AssetFallbackConfig {
577
589
scope : " /" . to_string (),
590
+ status_code : Some (StatusCode :: OK ),
578
591
}],
579
592
aliased_by : vec! [" /" . to_string ()],
580
593
encodings : vec! [
@@ -619,10 +632,6 @@ asset_router.certify_assets(assets, asset_configs).unwrap();
619
632
To delete the ` index.html ` asset, along with the fallback configuration for the ` / ` scope, the alias ` / ` and the alternative encodings:
620
633
621
634
``` rust
622
- # use ic_asset_certification :: {Asset , AssetConfig , AssetFallbackConfig , AssetRouter , AssetRedirectKind , AssetEncoding };
623
-
624
- # let mut asset_router = AssetRouter :: default ();
625
-
626
635
asset_router
627
636
. delete_assets (
628
637
vec! [
@@ -642,6 +651,7 @@ asset_router
642
651
)],
643
652
fallback_for : vec! [AssetFallbackConfig {
644
653
scope : " /" . to_string (),
654
+ status_code : Some (StatusCode :: OK ),
645
655
}],
646
656
aliased_by : vec! [" /" . to_string ()],
647
657
encodings : vec! [
@@ -656,10 +666,6 @@ asset_router
656
666
To delete the ` app.js ` asset, along with the alternative encodings:
657
667
658
668
``` rust
659
- # use ic_asset_certification :: {Asset , AssetConfig , AssetFallbackConfig , AssetRouter , AssetRedirectKind , AssetEncoding };
660
-
661
- # let mut asset_router = AssetRouter :: default ();
662
-
663
669
asset_router
664
670
. delete_assets (
665
671
vec! [
@@ -686,10 +692,6 @@ asset_router
686
692
To delete the ` css/app-ba74b708.css ` asset, along with the alternative encodings:
687
693
688
694
``` rust
689
- # use ic_asset_certification :: {Asset , AssetConfig , AssetFallbackConfig , AssetRouter , AssetRedirectKind , AssetEncoding };
690
-
691
- # let mut asset_router = AssetRouter :: default ();
692
-
693
695
asset_router . delete_assets (
694
696
vec! [
695
697
Asset :: new (
0 commit comments