Skip to content

Commit

Permalink
Percent encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmcd committed Jan 1, 2021
1 parent 4eaca6e commit ead237d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/S3/Extensions/S3+List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ extension S3 {
var headers = headers
headers.replaceOrAdd(name: "host", value: host)
let awsHeaders = try signer.headers(for: .GET, urlString: url, region: region, bucket: bucket, headers: headers, payload: .none)
return try make(request: url, method: .GET, headers: awsHeaders, data: emptyData()).flatMapThrowing { response in
return try make(request: url.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? url.absoluteString,
method: .GET,
headers: awsHeaders,
data: emptyData()
).flatMapThrowing { response in
try self.check(response)
return try response.decode(to: BucketResults.self)
}
Expand Down
12 changes: 12 additions & 0 deletions Sources/S3/Extensions/S3+Private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ extension S3 {
}
}
}

/// Make an S3 request
func make(request url: String, method: HTTPMethod, headers: HTTPHeaders, data: Data? = nil) throws -> EventLoopFuture<ClientResponse> {
return self.client.send(method, headers: headers, to: URI(string: url)) { req in
if let data = data {
var buffer = ByteBufferAllocator().buffer(capacity: data.count)
buffer.writeBytes(data)

req.body = buffer
}
}
}
}

0 comments on commit ead237d

Please sign in to comment.