Skip to content

Commit

Permalink
Merge pull request #45 from swift-aws/fixParamsInPath
Browse files Browse the repository at this point in the history
handle when path includes query params
  • Loading branch information
jonnymacs authored Jan 12, 2019
2 parents e1d6f95 + 929fbae commit ee093b1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/AWSSDKSwiftCore/AWSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,18 @@ extension AWSClient {
}
}

urlComponents.path = path
guard let parsedPath = URLComponents(string: path) else {
throw RequestError.invalidURL("\(endpoint)\(path)")
}

urlComponents.path = parsedPath.path

if let pathQueryItems = parsedPath.queryItems {
for item in pathQueryItems {
queryParams[item.name] = item.value
}
}

urlComponents.queryItems = urlQueryItems(fromDictionary: queryParams)

guard let url = urlComponents.url else {
Expand Down
48 changes: 48 additions & 0 deletions Tests/AWSSDKSwiftCoreTests/AWSClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ class AWSClientTests: XCTestCase {
} catch {
XCTFail(error.localizedDescription)
}

let s3Client = AWSClient(
accessKeyId: "foo",
secretAccessKey: "bar",
region: nil,
service: "s3",
serviceProtocol: ServiceProtocol(type: .restxml),
apiVersion: "2006-03-01",
endpoint: nil,
serviceEndpoints: ["us-west-2": "s3.us-west-2.amazonaws.com", "eu-west-1": "s3.eu-west-1.amazonaws.com", "us-east-1": "s3.amazonaws.com", "ap-northeast-1": "s3.ap-northeast-1.amazonaws.com", "s3-external-1": "s3-external-1.amazonaws.com", "ap-southeast-2": "s3.ap-southeast-2.amazonaws.com", "sa-east-1": "s3.sa-east-1.amazonaws.com", "ap-southeast-1": "s3.ap-southeast-1.amazonaws.com", "us-west-1": "s3.us-west-1.amazonaws.com"],
partitionEndpoint: "us-east-1",
middlewares: [],
possibleErrorTypes: [S3ErrorType.self]
)

do {
let awsRequest = try s3Client.debugCreateAWSRequest(
operation: "ListObjectsV2",
path: "/Bucket?list-type=2",
httpMethod: "GET",
input: input
)

XCTAssertEqual(awsRequest.url.absoluteString, "https://s3.amazonaws.com/Bucket?list-type=2")
_ = try awsRequest.toNIORequest()
} catch {
XCTFail(error.localizedDescription)
}
}

static var allTests : [(String, (AWSClientTests) -> () throws -> Void)] {
Expand Down Expand Up @@ -123,3 +151,23 @@ extension SESErrorType {
}
}
}

/// Error enum for S3
public enum S3ErrorType: AWSErrorType {
case noSuchKey(message: String?)
}

extension S3ErrorType {
public init?(errorCode: String, message: String?){
var errorCode = errorCode
if let index = errorCode.index(of: "#") {
errorCode = String(errorCode[errorCode.index(index, offsetBy: 1)...])
}
switch errorCode {
case "NoSuchKey":
self = .noSuchKey(message: message)
default:
return nil
}
}
}

0 comments on commit ee093b1

Please sign in to comment.