Moya : 8.0.3
Language : Swift 3.1
let urlString = "https://google.com/123/somepath?X-ABC-Asd=123"
Alamofire :Alamofire.upload(fileURL, to: URL(string: urlString)!, method: .put, headers: nil).response {
response in
print(response)
}
it all seems fine(don't look at status code):

enum MyApi {
case upload
}
extension MyApi : TargetType {
var baseURL: URL {
let urlString = "https://google.com/123/somepath?X-ABC-Asd=123"
return URL(string: urlString)!
}
var path: String {
return ""
}
...
}
provider.request(MyApi.upload)
The created request URL is different that in Alamofire request.

? character moya inserts the / char.https://google.com/123/somepath?X-ABC-Asd=123
https://google.com/123/somepath/?X-ABC-Asd=123
Could you help me and tell me what I'm doing wrong?
Hey @k8mil, can you check if it works as expected when you change your baseURL to be just https://google.com and path to return /123/somepath?X-ABC-Asd=123?
@pedrovereza
Thanks for your response.
I've created a sample repo with the test code. Just clone and run it.
https://github.com/k8mil/MoyaBaseURL
Below you can see, screen from Charles with 3 options:
request was performed with Alamofire using
URL(string: "https://google.com/123/somepath?X-ABC-Asd=123")!
request was performed using MoyaProvider with
baseURL = "https://google.com/123/somepath?X-ABC-Asd=123"
request was performed using MoyaProvider with
baseURL = "https://google.com and path = "/123/somepath?X-ABC-Asd=123"

And only Alamofire produces that what I want to achieve :)
Important thing is that I'm using Moya in my project and the consuming my backend API with Moya is really great and works perfectly, but I have some case that I have to use the URL(which is not related with backedAPI) that I received from some service and I shouldn't modify that URL. Unfortunately, as you can see in the Second and Thrid example the URL is modified by removing/changing the ? char.
Hey @k8mil thanks for the detailed explanation and examples 馃憤
I think I have a fix in #1053, care to take a look? 馃槈
Very interesting use case. Thanks for implementing this @pedrovereza 馃槃
Thanks @pedrovereza !
I've tested it and it works fine.
So, now I wait till it will be merged with master 馃憤 :)
URL+Moya.swift as below:public extension URL {
/// Initialize URL from Moya's `TargetType`.
init<T: TargetType>(target: T) {
// When a TargetType's path is empty, URL.appendingPathComponent may introduce trailing /, which may not be wanted in some cases
// See: https://github.com/Moya/Moya/pull/1053
// And: https://github.com/Moya/Moya/issues/1049
let targetPath = target.path
if targetPath.isEmpty {
self = target.baseURL
} else {
let tag = target.baseURL.absoluteString.hasSuffix("/") ? "" : "/"
self = .init(string: target.baseURL.absoluteString + tag + targetPath)!
}
}
}