Make addHeaders inout
This commit is contained in:
parent
87ecee13e6
commit
4abd2ab671
@ -71,9 +71,7 @@ public protocol SocketEnginePollable : SocketEngineSpec {
|
|||||||
|
|
||||||
// Default polling methods
|
// Default polling methods
|
||||||
extension SocketEnginePollable {
|
extension SocketEnginePollable {
|
||||||
private func addHeaders(for req: URLRequest) -> URLRequest {
|
private func addHeaders(to req: inout URLRequest) {
|
||||||
var req = req
|
|
||||||
|
|
||||||
if cookies != nil {
|
if cookies != nil {
|
||||||
let headers = HTTPCookie.requestHeaderFields(with: cookies!)
|
let headers = HTTPCookie.requestHeaderFields(with: cookies!)
|
||||||
req.allHTTPHeaderFields = headers
|
req.allHTTPHeaderFields = headers
|
||||||
@ -84,8 +82,6 @@ extension SocketEnginePollable {
|
|||||||
req.setValue(value, forHTTPHeaderField: headerName)
|
req.setValue(value, forHTTPHeaderField: headerName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return req
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRequestForPostWithPostWait() -> URLRequest {
|
func createRequestForPostWithPostWait() -> URLRequest {
|
||||||
@ -104,11 +100,10 @@ extension SocketEnginePollable {
|
|||||||
var req = URLRequest(url: urlPollingWithSid)
|
var req = URLRequest(url: urlPollingWithSid)
|
||||||
let postData = postStr.data(using: .utf8, allowLossyConversion: false)!
|
let postData = postStr.data(using: .utf8, allowLossyConversion: false)!
|
||||||
|
|
||||||
req = addHeaders(for: req)
|
addHeaders(to: &req)
|
||||||
|
|
||||||
req.httpMethod = "POST"
|
req.httpMethod = "POST"
|
||||||
req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")
|
req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
req.httpBody = postData
|
req.httpBody = postData
|
||||||
req.setValue(String(postData.count), forHTTPHeaderField: "Content-Length")
|
req.setValue(String(postData.count), forHTTPHeaderField: "Content-Length")
|
||||||
|
|
||||||
@ -124,9 +119,9 @@ extension SocketEnginePollable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var req = URLRequest(url: urlPollingWithSid)
|
var req = URLRequest(url: urlPollingWithSid)
|
||||||
req = addHeaders(for: req)
|
addHeaders(to: &req)
|
||||||
|
|
||||||
doLongPoll(for: req )
|
doLongPoll(for: req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRequest(for req: URLRequest, callbackWith callback: @escaping (Data?, URLResponse?, Error?) -> Void) {
|
func doRequest(for req: URLRequest, callbackWith callback: @escaping (Data?, URLResponse?, Error?) -> Void) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user