Skip to content

Commit 2afa75a

Browse files
Allow to set optional headers (#1456)
* Allow to set optional headers, that are passed on to Phoenix when the LiveView makes the initial connection * Update Sources/LiveViewNative/Coordinators/LiveSessionConfiguration.swift Co-authored-by: Carson Katri <[email protected]> Signed-off-by: Adrian Schönig <[email protected]> * Update Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift Co-authored-by: Carson Katri <[email protected]> Signed-off-by: Adrian Schönig <[email protected]> * Make `headers` nil by default * Update CHANGELOG.md --------- Signed-off-by: Adrian Schönig <[email protected]> Co-authored-by: Carson Katri <[email protected]>
1 parent 4e8fcf3 commit 2afa75a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## Added
1111
- `LiveViewNative.SwiftUI.normalize_os_version/1`
1212
- `LiveViewNative.SwiftUI.normalize_app_version/1`
13+
- Optional `LiveSessionConfiguration.headers`, sent when fetching the dead render (#1456)
1314

1415
## Changed
1516
- Submitting a form will remove focus from all fields (#1451)

Sources/LiveViewNative/Coordinators/LiveSessionConfiguration.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public struct LiveSessionConfiguration {
1515
///
1616
/// By default, no connection params are provided.
1717
public var connectParams: ((URL) -> [String: Any])? = nil
18+
19+
/// Optional headers that are sent when fetching the dead render.
20+
///
21+
/// By default, no additional headers are provided.
22+
public var headers: [String: String]? = nil
1823

1924
/// The URL session configuration the coordinator will use for performing HTTP and socket requests.
2025
///
@@ -34,10 +39,12 @@ public struct LiveSessionConfiguration {
3439

3540
public init(
3641
connectParams: ((URL) -> [String: Any])? = nil,
42+
headers: [String: String]? = nil,
3743
urlSessionConfiguration: URLSessionConfiguration = .default,
3844
transition: AnyTransition? = nil,
3945
reconnectBehavior: ReconnectBehavior = .exponential
4046
) {
47+
self.headers = headers
4148
self.connectParams = connectParams
4249
self.urlSessionConfiguration = urlSessionConfiguration
4350
self.transition = transition

Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
349349

350350
var request = request
351351
request.url = request.url!.appendingLiveViewItems()
352+
request.allHTTPHeaderFields = configuration.headers
353+
352354
if let domValues {
353355
request.setValue(domValues.phxCSRFToken, forHTTPHeaderField: "x-csrf-token")
354356
}

0 commit comments

Comments
 (0)