@@ -932,11 +932,19 @@ impl Allowlist for DialogAllowlistConfig {
932932 }
933933}
934934
935+ /// HTTP API scope definition.
936+ /// It is a list of URLs that can be accessed by the webview when using the HTTP APIs.
937+ #[ derive( Debug , Default , PartialEq , Clone , Deserialize , Serialize ) ]
938+ #[ cfg_attr( feature = "schema" , derive( JsonSchema ) ) ]
939+ pub struct HttpAllowlistScope ( pub Vec < Url > ) ;
940+
935941/// Allowlist for the HTTP APIs.
936942#[ derive( Debug , Default , PartialEq , Clone , Deserialize , Serialize ) ]
937943#[ cfg_attr( feature = "schema" , derive( JsonSchema ) ) ]
938944#[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
939945pub struct HttpAllowlistConfig {
946+ /// The access scope for the HTTP APIs.
947+ pub scope : HttpAllowlistScope ,
940948 /// Use this flag to enable all HTTP API features.
941949 #[ serde( default ) ]
942950 pub all : bool ,
@@ -948,6 +956,7 @@ pub struct HttpAllowlistConfig {
948956impl Allowlist for HttpAllowlistConfig {
949957 fn all_features ( ) -> Vec < & ' static str > {
950958 let allowlist = Self {
959+ scope : Default :: default ( ) ,
951960 all : false ,
952961 request : true ,
953962 } ;
@@ -1653,6 +1662,12 @@ mod build {
16531662 quote ! { :: std:: path:: PathBuf :: from( #s) }
16541663 }
16551664
1665+ /// Creates a `Url` constructor `TokenStream`.
1666+ fn url_lit ( url : & Url ) -> TokenStream {
1667+ let url = url. as_str ( ) ;
1668+ quote ! { #url. parse( ) . unwrap( ) }
1669+ }
1670+
16561671 /// Create a map constructor, mapping keys and values with other `TokenStream`s.
16571672 ///
16581673 /// This function is pretty generic because the types of keys AND values get transformed.
@@ -1758,8 +1773,8 @@ mod build {
17581773 quote ! { #prefix:: App ( #path) }
17591774 }
17601775 Self :: External ( url) => {
1761- let url = url . as_str ( ) ;
1762- quote ! { #prefix:: External ( #url. parse ( ) . unwrap ( ) ) }
1776+ let url = url_lit ( url ) ;
1777+ quote ! { #prefix:: External ( #url) }
17631778 }
17641779 } )
17651780 }
@@ -2041,12 +2056,27 @@ mod build {
20412056 }
20422057 }
20432058
2059+ impl ToTokens for HttpAllowlistScope {
2060+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
2061+ let allowed_urls = vec_lit ( & self . 0 , url_lit) ;
2062+ tokens. append_all ( quote ! { :: tauri:: utils:: config:: HttpAllowlistScope ( #allowed_urls) } )
2063+ }
2064+ }
2065+
2066+ impl ToTokens for HttpAllowlistConfig {
2067+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
2068+ let scope = & self . scope ;
2069+ tokens. append_all ( quote ! { :: tauri:: utils:: config:: HttpAllowlistConfig { scope: #scope, ..Default :: default ( ) } } )
2070+ }
2071+ }
2072+
20442073 impl ToTokens for AllowlistConfig {
20452074 fn to_tokens ( & self , tokens : & mut TokenStream ) {
20462075 let fs = & self . fs ;
20472076 let protocol = & self . protocol ;
2077+ let http = & self . http ;
20482078 tokens. append_all (
2049- quote ! { :: tauri:: utils:: config:: AllowlistConfig { fs: #fs, protocol: #protocol, ..Default :: default ( ) } } ,
2079+ quote ! { :: tauri:: utils:: config:: AllowlistConfig { fs: #fs, protocol: #protocol, http : #http , ..Default :: default ( ) } } ,
20502080 )
20512081 }
20522082 }
0 commit comments