Skip to content

Commit

Permalink
Fixed an issue of baseURL
Browse files Browse the repository at this point in the history
Added multiple test cases to test related to baseURL.
Also, added some tests like "https://example.com///foo//bar//" to ensure
how createTaskInURLSession() should handle multiple / delimiters.
  • Loading branch information
Ono Masashi committed Sep 4, 2015
1 parent b82ae1d commit c86e023
Show file tree
Hide file tree
Showing 2 changed files with 424 additions and 7 deletions.
7 changes: 2 additions & 5 deletions APIKit/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public extension Request {

// Use Result here because `throws` loses type info of an error (in Swift 2 beta 2)
internal func createTaskInURLSession(URLSession: NSURLSession) -> Result<NSURLSessionDataTask, APIError> {
guard let components = NSURLComponents(URL: baseURL, resolvingAgainstBaseURL: true) else {
let URL = path.isEmpty ? baseURL : baseURL.URLByAppendingPathComponent(path)
guard let components = NSURLComponents(URL: URL, resolvingAgainstBaseURL: true) else {
return .Failure(.InvalidBaseURL(baseURL))
}

Expand All @@ -90,10 +91,6 @@ public extension Request {
}
}

if (!path.isEmpty) {
components.path = path.hasPrefix("/") ? path : "/" + path
}

URLRequest.URL = components.URL
URLRequest.HTTPMethod = method.rawValue
URLRequest.setValue(requestBodyBuilder.contentTypeHeader, forHTTPHeaderField: "Content-Type")
Expand Down
Loading

0 comments on commit c86e023

Please sign in to comment.