Skip to content

Commit

Permalink
Merge pull request #13 from onurhuseyincantay/develop
Browse files Browse the repository at this point in the history
Hotfix Celullar Access
  • Loading branch information
onurhuseyincantay authored Oct 4, 2020
2 parents 708df4d + 488f8ee commit 03170a6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/Hover/URLRequest+prepareRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@
import Foundation

internal extension URLRequest {

private var headerField: String { "Authorization" }
private var contentTypeHeader: String { "Content-Type" }

mutating func prepareRequest(with target: NetworkTarget) {
let contentTypeHeaderName = contentTypeHeader
allHTTPHeaderFields = target.headers
allowsCellularAccess = false
setValue(target.contentType?.rawValue, forHTTPHeaderField: contentTypeHeaderName)
prepareAuthorization(with: target.providerType)
httpMethod = target.methodType.methodName
}

private mutating func prepareAuthorization(with authType: AuthProviderType) {
switch authType {
case .basic(let username, let password):
let loginString = String(format: "%@:%@", username, password)
guard let data = loginString.data(using: .utf8) else { return }
setValue("Basic \(data.base64EncodedString())", forHTTPHeaderField: headerField)

case .bearer(let token):
setValue("Bearer \(token)", forHTTPHeaderField: headerField)

case .none: break
}
}
Expand Down

0 comments on commit 03170a6

Please sign in to comment.