Skip to content

Commit 23e438d

Browse files
committed
Fixed bogus host
When no host is specified by client code, use the hard-coded default as the base URL rather than a scheme with no host.
1 parent 10e5f7c commit 23e438d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

MapboxGeocoder/MBGeocoder.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ public class MBGeocoder: NSObject {
2323
- param host: An optional hostname to the server API. The Mapbox Geocoding API endpoint is used by default.
2424
*/
2525
public init(accessToken: String, host: String? = nil) {
26-
let baseURLComponents = NSURLComponents()
27-
baseURLComponents.scheme = "https"
28-
baseURLComponents.host = host
29-
configuration = MBGeocoderConfiguration(accessToken, apiEndpoint: baseURLComponents.string)
26+
configuration = MBGeocoderConfiguration(accessToken, host: host)
3027
}
3128

3229
private var task: NSURLSessionDataTask?

MapboxGeocoder/MBGeocoderConfiguration.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ internal struct MBGeocoderConfiguration: Configuration {
55
internal var apiEndpoint: String = "https://api.mapbox.com"
66
internal var accessToken: String?
77

8-
internal init(_ accessToken: String, apiEndpoint: String? = nil) {
8+
internal init(_ accessToken: String, host: String? = nil) {
99
self.accessToken = accessToken
10-
self.apiEndpoint = apiEndpoint ?? self.apiEndpoint
10+
if let host = host {
11+
let baseURLComponents = NSURLComponents()
12+
baseURLComponents.scheme = "https"
13+
baseURLComponents.host = host
14+
apiEndpoint = baseURLComponents.string ?? apiEndpoint
15+
}
1116
}
1217
}

0 commit comments

Comments
 (0)