Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the double encoding problem and used a method from Params Extensions #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions Sources/Networking/NetworkingRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,24 @@ public class NetworkingRequest: NSObject, URLSessionTaskDelegate {

private func getURLWithParams() -> String {
let urlString = baseURL + route
if params.isEmpty { return urlString }
guard let url = URL(string: urlString) else {
guard !params.isEmpty, let url = URL(string: urlString) else {
return urlString
}
if var urlComponents = URLComponents(url: url ,resolvingAgainstBaseURL: false) {
var queryItems = urlComponents.queryItems ?? [URLQueryItem]()
params.forEach { param in
// arrayParam[] syntax
if let array = param.value as? [CustomStringConvertible] {
array.forEach {
queryItems.append(URLQueryItem(name: "\(param.key)[]", value: "\($0)"))
}
}
queryItems.append(URLQueryItem(name: param.key, value: "\(param.value)"))
}
urlComponents.queryItems = queryItems
return urlComponents.url?.absoluteString ?? urlString

guard var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
return urlString
}
return urlString

urlComponents.queryItems = params.map { key, value in
URLQueryItem(name: key, value: "\(value)")
}

let query = params.asPercentEncodedString()
urlComponents.percentEncodedQuery = query

return urlComponents.url?.absoluteString ?? urlString
}

internal func buildURLRequest() -> URLRequest? {
var urlString = baseURL + route
if httpMethod == .get {
Expand Down