Skip to content

Commit

Permalink
Merge pull request soto-project#69 from tengyifei/patch-1
Browse files Browse the repository at this point in the history
Fix duplicate bucket name in URL normalization
  • Loading branch information
noppoMan authored Apr 14, 2018
2 parents 8d744d4 + da8ce4c commit 265b8d7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/AWSSDKSwift/Middlewares/S3/S3RequestMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ struct S3RequestMiddleware: AWSRequestMiddleware {
}
request.url = URL(string: "\(request.url.scheme ?? "https")://\(paths.removeFirst()).\(domain)/\(paths.joined(separator: "/"))\(query)")!
default:
guard let host = request.url.host, host.contains("amazonaws.com") else { break }
guard let host = request.url.host, host.contains("amazonaws.com") else { break }
var pathes = request.url.path.components(separatedBy: "/")
if paths.count > 1 {
_ = pathes.removeFirst() // /
let bucket = pathes.removeFirst() // bucket
var urlString = "https://\(bucket).\(host)/\(pathes.joined(separator: "/"))"
var urlString: String
if let firstHostComponent = host.components(separatedBy: ".").first, bucket == firstHostComponent {
// Bucket name is part of host. No need to append bucket
urlString = "https://\(host)/\(pathes.joined(separator: "/"))"
} else {
urlString = "https://\(bucket).\(host)/\(pathes.joined(separator: "/"))"
}
if let query = request.url.query {
urlString += "?\(query)"
}
Expand Down

0 comments on commit 265b8d7

Please sign in to comment.