@@ -20,6 +20,9 @@ class OSIABWebViewModel: NSObject, ObservableObject {
2020 /// Indicates if first load is already done. This is important in order to trigger the `browserPageLoad` event.
2121 private var firstLoadDone : Bool = false
2222
23+ /// Custom headers to be used by the WebView.
24+ private let customHeaders : [ String : String ] ?
25+
2326 /// The current URL being displayed
2427 @Published private( set) var url : URL
2528 /// Indicates if the URL is being loaded into the screen.
@@ -46,6 +49,7 @@ class OSIABWebViewModel: NSObject, ObservableObject {
4649 /// - callbackHandler: Object that manages all the callbacks available for the WebView.
4750 init (
4851 url: URL ,
52+ customHeaders: [ String : String ] ? = nil ,
4953 _ webViewConfiguration: WKWebViewConfiguration ,
5054 _ scrollViewBounces: Bool = true ,
5155 _ customUserAgent: String ? = nil ,
@@ -54,6 +58,7 @@ class OSIABWebViewModel: NSObject, ObservableObject {
5458 callbackHandler: OSIABWebViewCallbackHandler
5559 ) {
5660 self . url = url
61+ self . customHeaders = customHeaders
5762 self . webView = . init( frame: . zero, configuration: webViewConfiguration)
5863 self . closeButtonText = uiModel. closeButtonText
5964 self . callbackHandler = callbackHandler
@@ -133,7 +138,13 @@ class OSIABWebViewModel: NSObject, ObservableObject {
133138
134139 /// Loads the URL within the WebView. Is the first operation to be performed when the view is displayed.
135140 func loadURL( ) {
136- self . webView. load ( . init( url: self . url) )
141+ var request = URLRequest ( url: self . url)
142+ if let headers = self . customHeaders {
143+ for (key, value) in headers {
144+ request. setValue ( value, forHTTPHeaderField: key)
145+ }
146+ }
147+ self . webView. load ( request)
137148 }
138149
139150 /// Signals the WebView to move forward. This is performed as a reaction to a button click.
0 commit comments