-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from ministero-salute/feat/custom-header
feat: custom header
- Loading branch information
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
DGCAVerifier/Services/GatewayConnection/CustomHeaderInterceptor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// CustomHeaderInterceptor.swift | ||
// Verifier | ||
// | ||
// Created by Davide Aliti on 14/03/22. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
struct CustomHeaderInterceptor: RequestInterceptor { | ||
|
||
func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) { | ||
var urlRequest = urlRequest | ||
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] | ||
let iosVersion = ProcessInfo.processInfo.operatingSystemVersionString | ||
let formattedIOSVersion = iosVersion.replacingOccurrences(of: "Version ", with: "").replacingOccurrences(of: " (Build ", with: "; Build/") | ||
let customHeader = HTTPHeader(name: "User-Agent", value: "DGCAVerifierIOS / \(appVersion ?? "") (iOS \(formattedIOSVersion)") | ||
urlRequest.headers.add(customHeader) | ||
completion(.success(urlRequest)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters