Skip to content

Commit

Permalink
feat: custom header
Browse files Browse the repository at this point in the history
add custom header interceptor
  • Loading branch information
Light2288 committed Mar 14, 2022
1 parent b90e328 commit 8b2be28
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GatewayConnection {

// Init session
let evaluators = [certificateEvaluator: PinnedCertificatesTrustEvaluator(certificates: [certificate])]
session = Session(serverTrustManager: ServerTrustManager(evaluators: evaluators))
session = Session(interceptor: CustomHeaderInterceptor(), serverTrustManager: ServerTrustManager(evaluators: evaluators))
}

func initialize(completion: (()->())? = nil) {
Expand Down
6 changes: 6 additions & 0 deletions Verifier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@
6B797DDD26D052B800EB2873 /* Data+SHA256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B797DDC26D052B800EB2873 /* Data+SHA256.swift */; };
6B797DDE26D052B800EB2873 /* Data+SHA256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B797DDC26D052B800EB2873 /* Data+SHA256.swift */; };
6BA8B9E5266FAC150060D767 /* GatewayConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4F3C442649D60B00F59BA2 /* GatewayConnection.swift */; };
6BF86E2F27DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */; };
6BF86E3027DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */; };
9020C5E12721600D00F45CA7 /* String+Char.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653F929126B00F9C000BE8F5 /* String+Char.swift */; };
9020C5E32721600D00F45CA7 /* UILabel+Inspectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65021B3F26AEC142004C3D14 /* UILabel+Inspectable.swift */; };
9020C5E42721600D00F45CA7 /* UIImageView+Inspectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65021B5826AECF59004C3D14 /* UIImageView+Inspectable.swift */; };
Expand Down Expand Up @@ -564,6 +566,7 @@
6BA8B9E1266F7E4C0060D767 /* RecoveryValidityCheckTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecoveryValidityCheckTests.swift; sourceTree = "<group>"; };
6BA8B9E3266F840B0060D767 /* TestValidityCheckTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestValidityCheckTests.swift; sourceTree = "<group>"; };
6BA8B9E72671227C0060D767 /* LocalDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalDataTests.swift; sourceTree = "<group>"; };
6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHeaderInterceptor.swift; sourceTree = "<group>"; };
902155CF274E55490020DA88 /* StatementValidityCheck.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementValidityCheck.swift; sourceTree = "<group>"; };
902BB46B27AD852400C397EB /* TestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestModel.swift; sourceTree = "<group>"; };
9037A0A5270EFD2D0067DCF8 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1198,6 +1201,7 @@
65EFB5ED26B04D850081682B /* GatewayConnection+Certificates.swift */,
65EFB5F026B04D900081682B /* GatewayConnection+Settings.swift */,
65F280C726D65269009BC452 /* GatewayConnection+Revocation.swift */,
6BF86E2E27DF4D8A002DF298 /* CustomHeaderInterceptor.swift */,
);
path = GatewayConnection;
sourceTree = "<group>";
Expand Down Expand Up @@ -1822,6 +1826,7 @@
658CB71C26AF27D200B90EC0 /* UIBarButtonItem+Appearance.swift in Sources */,
65F280D226D658CB009BC452 /* CRL+Entity.swift in Sources */,
65E7000226AF6E1F00715CCC /* UIStackView+ArrangedSubViews.swift in Sources */,
6BF86E3027DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */,
14C3B3CF27BD47CC00C2C2A7 /* CustomPickerController.swift in Sources */,
659605FA26E7A6E0008AD4E2 /* CRLProgress.swift in Sources */,
65021B4D26AEC889004C3D14 /* ButtonStyle.swift in Sources */,
Expand Down Expand Up @@ -2026,6 +2031,7 @@
65E7001326AF7BB000715CCC /* FaqView.swift in Sources */,
65F280D126D658CB009BC452 /* CRL+Entity.swift in Sources */,
9F4F3C5A2649D60C00F59BA2 /* MainCoordinator.swift in Sources */,
6BF86E2F27DF4D8A002DF298 /* CustomHeaderInterceptor.swift in Sources */,
98BF53D227A987F500B8FB1A /* HCertValidator.swift in Sources */,
659605F326E7911E008AD4E2 /* ProgressView.swift in Sources */,
653F928A26B00474000BE8F5 /* CountryCell.swift in Sources */,
Expand Down

0 comments on commit 8b2be28

Please sign in to comment.