-
-
Notifications
You must be signed in to change notification settings - Fork 32
Description
I am using WS to send requests to an API, and my request always fails when the verb is DELETE.
I have digged into it and the reason is that for the DELETE requests the parameters Encoding is always set to "URLEncoding.default", even if in my implementation I try to pass a different one.
In the method is buildRequest() in the WSRequest.swift file, there is this code which sets the encoding to URLEncoding.default for anything else than POST or PUT:
var request: URLRequest?
if httpVerb == .post || httpVerb == .put {
request = try? postParameterEncoding.encode(r, with: params)
} else {
request = try? URLEncoding.default.encode(r, with: params)
}
return request ?? r
I have change this to the following:
var request: URLRequest?
if httpVerb == .post || httpVerb == .put || httpVerb == .delete {
request = try? postParameterEncoding.encode(r, with: params)
} else {
request = try? URLEncoding.default.encode(r, with: params)
}
return request ?? r
And now the DELETE requests work fine.
However when I'll download future updates I'll have to do it again.
Would it not be better to just have this:
var request: URLRequest?
request = try? postParameterEncoding.encode(r, with: params)
return request ?? r
And let the user pass the encoding needed?
Thanks