From 0d0ae7191681ed753d28a841d3886909e211baf4 Mon Sep 17 00:00:00 2001 From: Aliona Date: Wed, 11 Jul 2018 17:23:05 +0300 Subject: [PATCH] Add assertion failure --- .../NetworkServiceConfiguration.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift b/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift index 2e903757..da508be3 100644 --- a/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift +++ b/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift @@ -59,19 +59,19 @@ public struct NetworkServiceConfiguration { sessionConfiguration.timeoutIntervalForResource = timeoutInterval sessionConfiguration.httpAdditionalHeaders = additionalHttpHeaders - let urlKey = String.parseHost(from: baseUrl) + let urlKey = baseUrl.parseHost() serverTrustPolicies = [urlKey: .disableEvaluation] } } private extension String { - static func parseHost(from string: String) -> String { - return URL(string: string)?.host ?? string - .replacingOccurrences(of: "https://", with: "") - .replacingOccurrences(of: "http://", with: "") - .components(separatedBy: "/") - .first ?? "" + func parseHost() -> String { + guard let host = URL(string: self)?.host else { + assertionFailure("Cannot detect host for base URL") + return "" + } + return host } }