@@ -16,7 +16,6 @@ use std::{cell::RefCell, collections::HashMap};
16
16
17
17
#[ init]
18
18
fn init ( ) {
19
- prepare_cel_exprs ( ) ;
20
19
certify_all_assets ( ) ;
21
20
}
22
21
@@ -41,38 +40,26 @@ thread_local! {
41
40
static HTTP_TREE : RefCell <HttpCertificationTree > = RefCell :: new( HttpCertificationTree :: default ( ) ) ;
42
41
static ENCODED_RESPONSES : RefCell <HashMap <( String , String ) , CertifiedHttpResponse <' static >>> = RefCell :: new( HashMap :: new( ) ) ;
43
42
static RESPONSES : RefCell <HashMap <String , CertifiedHttpResponse <' static >>> = RefCell :: new( HashMap :: new( ) ) ;
44
- static CEL_EXPRS : RefCell <HashMap <String , ( DefaultResponseOnlyCelExpression <' static >, String ) >> = RefCell :: new( HashMap :: new( ) ) ;
45
43
}
46
44
47
45
static ASSETS_DIR : Dir < ' _ > = include_dir ! ( "$CARGO_MANIFEST_DIR/../frontend/dist" ) ;
48
46
49
47
lazy_static ! {
50
- static ref ASSET_CEL_EXPR_PATH : & ' static str = "assets" ;
51
48
static ref INDEX_REQ_PATH : & ' static str = "" ;
52
49
static ref INDEX_TREE_PATH : HttpCertificationPath <' static > =
53
50
HttpCertificationPath :: wildcard( * INDEX_REQ_PATH ) ;
54
51
static ref INDEX_FILE_PATH : & ' static str = "index.html" ;
52
+ static ref ASSET_CEL_EXPR_DEF : DefaultResponseOnlyCelExpression <' static > =
53
+ DefaultCelBuilder :: response_only_certification( )
54
+ . with_response_certification( DefaultResponseCertification :: response_header_exclusions(
55
+ vec![ ] ,
56
+ ) )
57
+ . build( ) ;
58
+ static ref ASSET_CEL_EXPR : String = ASSET_CEL_EXPR_DEF . to_string( ) ;
55
59
}
56
60
57
61
// Certification
58
62
59
- fn prepare_cel_exprs ( ) {
60
- let asset_cel_expr_def = DefaultCelBuilder :: response_only_certification ( )
61
- . with_response_certification ( DefaultResponseCertification :: response_header_exclusions (
62
- vec ! [ ] ,
63
- ) )
64
- . build ( ) ;
65
-
66
- let asset_cel_expr = asset_cel_expr_def. to_string ( ) ;
67
-
68
- CEL_EXPRS . with_borrow_mut ( |exprs| {
69
- exprs. insert (
70
- ASSET_CEL_EXPR_PATH . to_string ( ) ,
71
- ( asset_cel_expr_def, asset_cel_expr) ,
72
- ) ;
73
- } ) ;
74
- }
75
-
76
63
fn certify_all_assets ( ) {
77
64
add_certification_skips ( ) ;
78
65
@@ -202,55 +189,12 @@ fn certify_asset_with_encoding(
202
189
let mut headers = vec ! [ ( "content-encoding" . to_string( ) , encoding. to_string( ) ) ] ;
203
190
headers. extend ( additional_headers) ;
204
191
205
- CEL_EXPRS . with_borrow ( |cel_exprs| {
206
- // get the relevant CEL expression
207
- let ( cel_expr_def, cel_expr_str) = cel_exprs. get ( * ASSET_CEL_EXPR_PATH ) . unwrap ( ) ;
208
-
209
- // create the response
210
- let response = create_asset_response ( headers, body, cel_expr_str. to_string ( ) ) ;
211
-
212
- // certify the response
213
- let certification =
214
- HttpCertification :: response_only ( cel_expr_def, & response, None ) . unwrap ( ) ;
215
-
216
- HTTP_TREE . with_borrow_mut ( |http_tree| {
217
- // add the certification to the certification tree
218
- http_tree. insert ( & HttpCertificationTreeEntry :: new (
219
- asset_tree_path,
220
- & certification,
221
- ) ) ;
222
- } ) ;
223
-
224
- ENCODED_RESPONSES . with_borrow_mut ( |responses| {
225
- // store the response for later retrieval
226
- responses. insert (
227
- ( asset_req_path, encoding. to_string ( ) ) ,
228
- CertifiedHttpResponse {
229
- response,
230
- certification,
231
- } ,
232
- ) ;
233
- } ) ;
234
- } ) ;
235
- } ;
236
- }
237
-
238
- fn certify_asset_response (
239
- body : & ' static [ u8 ] ,
240
- additional_headers : Vec < HeaderField > ,
241
- asset_tree_path : & HttpCertificationPath ,
242
- asset_req_path : String ,
243
- ) {
244
- CEL_EXPRS . with_borrow ( |cel_exprs| {
245
- // get the relevant CEL expression
246
- let ( cel_expr_def, cel_expr_str) = cel_exprs. get ( * ASSET_CEL_EXPR_PATH ) . unwrap ( ) ;
247
-
248
192
// create the response
249
- let response = create_asset_response ( additional_headers , body, cel_expr_str . to_string ( ) ) ;
193
+ let response = create_asset_response ( headers , body, ASSET_CEL_EXPR . clone ( ) ) ;
250
194
251
195
// certify the response
252
196
let certification =
253
- HttpCertification :: response_only ( cel_expr_def , & response, None ) . unwrap ( ) ;
197
+ HttpCertification :: response_only ( & ASSET_CEL_EXPR_DEF , & response, None ) . unwrap ( ) ;
254
198
255
199
HTTP_TREE . with_borrow_mut ( |http_tree| {
256
200
// add the certification to the certification tree
@@ -260,16 +204,49 @@ fn certify_asset_response(
260
204
) ) ;
261
205
} ) ;
262
206
263
- RESPONSES . with_borrow_mut ( |responses| {
207
+ ENCODED_RESPONSES . with_borrow_mut ( |responses| {
264
208
// store the response for later retrieval
265
209
responses. insert (
266
- asset_req_path,
210
+ ( asset_req_path, encoding . to_string ( ) ) ,
267
211
CertifiedHttpResponse {
268
212
response,
269
213
certification,
270
214
} ,
271
215
) ;
272
216
} ) ;
217
+ } ;
218
+ }
219
+
220
+ fn certify_asset_response (
221
+ body : & ' static [ u8 ] ,
222
+ additional_headers : Vec < HeaderField > ,
223
+ asset_tree_path : & HttpCertificationPath ,
224
+ asset_req_path : String ,
225
+ ) {
226
+ // create the response
227
+ let response = create_asset_response ( additional_headers, body, ASSET_CEL_EXPR . clone ( ) ) ;
228
+
229
+ // certify the response
230
+ let certification =
231
+ HttpCertification :: response_only ( & ASSET_CEL_EXPR_DEF , & response, None ) . unwrap ( ) ;
232
+
233
+ HTTP_TREE . with_borrow_mut ( |http_tree| {
234
+ // add the certification to the certification tree
235
+ http_tree. insert ( & HttpCertificationTreeEntry :: new (
236
+ asset_tree_path,
237
+ & certification,
238
+ ) ) ;
239
+ } ) ;
240
+
241
+ RESPONSES . with_borrow_mut ( |responses| {
242
+ // store the response for later retrieval
243
+ responses. insert (
244
+ asset_req_path,
245
+ CertifiedHttpResponse {
246
+ response,
247
+ certification,
248
+ } ,
249
+ ) ;
273
250
} ) ;
274
251
}
275
252
0 commit comments