@@ -78,11 +78,19 @@ use std::{borrow::Cow, cell::RefCell, cmp, collections::HashMap, rc::Rc};
78
78
/// from: "/old-url".to_string(),
79
79
/// to: "/".to_string(),
80
80
/// kind: AssetRedirectKind::Permanent,
81
+ /// headers: vec![(
82
+ /// "content-type".to_string(),
83
+ /// "text/plain; charset=utf-8".to_string(),
84
+ /// )],
81
85
/// },
82
86
/// AssetConfig::Redirect {
83
87
/// from: "/css/app.css".to_string(),
84
88
/// to: "/css/app-ba74b708.css".to_string(),
85
89
/// kind: AssetRedirectKind::Temporary,
90
+ /// headers: vec![(
91
+ /// "content-type".to_string(),
92
+ /// "text/plain; charset=utf-8".to_string(),
93
+ /// )],
86
94
/// },
87
95
/// ];
88
96
///
@@ -311,8 +319,14 @@ impl<'content> AssetRouter<'content> {
311
319
}
312
320
313
321
for asset_config in asset_configs {
314
- if let NormalizedAssetConfig :: Redirect { from, to, kind } = asset_config {
315
- self . insert_redirect ( from, to, kind) ?;
322
+ if let NormalizedAssetConfig :: Redirect {
323
+ from,
324
+ to,
325
+ kind,
326
+ headers,
327
+ } = asset_config
328
+ {
329
+ self . insert_redirect ( from, to, kind, headers) ?;
316
330
}
317
331
}
318
332
@@ -367,8 +381,14 @@ impl<'content> AssetRouter<'content> {
367
381
}
368
382
369
383
for asset_config in asset_configs {
370
- if let NormalizedAssetConfig :: Redirect { from, to, kind } = asset_config {
371
- self . delete_redirect ( from, to, kind) ?;
384
+ if let NormalizedAssetConfig :: Redirect {
385
+ from,
386
+ to,
387
+ kind,
388
+ headers,
389
+ } = asset_config
390
+ {
391
+ self . delete_redirect ( from, to, kind, headers) ?;
372
392
}
373
393
}
374
394
@@ -799,8 +819,9 @@ impl<'content> AssetRouter<'content> {
799
819
from : String ,
800
820
to : String ,
801
821
kind : AssetRedirectKind ,
822
+ additional_headers : Vec < ( String , String ) > ,
802
823
) -> AssetCertificationResult < ( ) > {
803
- let response = Self :: prepare_redirect ( from. clone ( ) , to, kind) ?;
824
+ let response = Self :: prepare_redirect ( from. clone ( ) , to, kind, additional_headers ) ?;
804
825
805
826
self . tree . borrow_mut ( ) . insert ( & response. tree_entry ) ;
806
827
@@ -815,8 +836,9 @@ impl<'content> AssetRouter<'content> {
815
836
from : String ,
816
837
to : String ,
817
838
kind : AssetRedirectKind ,
839
+ addtional_headers : Vec < ( String , String ) > ,
818
840
) -> AssetCertificationResult < ( ) > {
819
- let response = Self :: prepare_redirect ( from. clone ( ) , to, kind) ?;
841
+ let response = Self :: prepare_redirect ( from. clone ( ) , to, kind, addtional_headers ) ?;
820
842
821
843
self . tree . borrow_mut ( ) . delete ( & response. tree_entry ) ;
822
844
self . responses . remove ( & RequestKey :: new ( & from, None , None ) ) ;
@@ -828,13 +850,15 @@ impl<'content> AssetRouter<'content> {
828
850
from : String ,
829
851
to : String ,
830
852
kind : AssetRedirectKind ,
853
+ addtional_headers : Vec < ( String , String ) > ,
831
854
) -> AssetCertificationResult < CertifiedAssetResponse < ' content > > {
832
855
let status_code = match kind {
833
856
AssetRedirectKind :: Permanent => StatusCode :: MOVED_PERMANENTLY ,
834
857
AssetRedirectKind :: Temporary => StatusCode :: TEMPORARY_REDIRECT ,
835
858
} ;
836
859
837
- let headers = vec ! [ ( "location" . to_string( ) , to) ] ;
860
+ let mut headers = vec ! [ ( "location" . to_string( ) , to) ] ;
861
+ headers. extend ( addtional_headers) ;
838
862
839
863
let ( response, certification) = Self :: prepare_response_and_certification (
840
864
from. clone ( ) ,
@@ -3309,6 +3333,10 @@ mod tests {
3309
3333
CERTIFICATE_EXPRESSION_HEADER_NAME . to_string( ) ,
3310
3334
cel_expr. clone( ) ,
3311
3335
) ,
3336
+ (
3337
+ "content-type" . to_string( ) ,
3338
+ "text/plain; charset=utf-8" . to_string( ) ,
3339
+ ) ,
3312
3340
] )
3313
3341
. build ( ) ;
3314
3342
let mut expected_old_url_response = HttpResponse :: builder ( )
@@ -3317,6 +3345,10 @@ mod tests {
3317
3345
( "content-length" . to_string( ) , "0" . to_string( ) ) ,
3318
3346
( "location" . to_string( ) , "/" . to_string( ) ) ,
3319
3347
( CERTIFICATE_EXPRESSION_HEADER_NAME . to_string( ) , cel_expr) ,
3348
+ (
3349
+ "content-type" . to_string( ) ,
3350
+ "text/plain; charset=utf-8" . to_string( ) ,
3351
+ ) ,
3320
3352
] )
3321
3353
. build ( ) ;
3322
3354
@@ -3891,6 +3923,10 @@ mod tests {
3891
3923
from : "/old-url" . to_string ( ) ,
3892
3924
to : "/" . to_string ( ) ,
3893
3925
kind : AssetRedirectKind :: Permanent ,
3926
+ headers : vec ! [ (
3927
+ "content-type" . to_string( ) ,
3928
+ "text/plain; charset=utf-8" . to_string( ) ,
3929
+ ) ] ,
3894
3930
}
3895
3931
}
3896
3932
@@ -3900,6 +3936,10 @@ mod tests {
3900
3936
from : "/css/app.css" . to_string ( ) ,
3901
3937
to : "/css/app-ba74b708.css" . to_string ( ) ,
3902
3938
kind : AssetRedirectKind :: Temporary ,
3939
+ headers : vec ! [ (
3940
+ "content-type" . to_string( ) ,
3941
+ "text/plain; charset=utf-8" . to_string( ) ,
3942
+ ) ] ,
3903
3943
}
3904
3944
}
3905
3945
0 commit comments