Skip to content

Added passing cookies from long polling session to web scoket #1058

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

Merged
merged 3 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Source/SocketIO/Engine/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
private func createWebSocketAndConnect() {
var req = URLRequest(url: urlWebSocketWithSid)

addHeaders(to: &req)
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies)

ws = WebSocket(request: req)
ws?.callbackQueue = engineQueue
Expand Down
11 changes: 7 additions & 4 deletions Source/SocketIO/Engine/SocketEngineSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ extension SocketEngineSpec {
return com.url!
}

func addHeaders(to req: inout URLRequest) {
if let cookies = cookies {
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookies)
func addHeaders(to req: inout URLRequest, includingCookies additionalCookies: [HTTPCookie]? = nil) {
var cookiesToAdd: [HTTPCookie] = cookies ?? []
cookiesToAdd += additionalCookies ?? []

if !cookiesToAdd.isEmpty {
req.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookiesToAdd)
}

if let extraHeaders = extraHeaders {
for (headerName, value) in extraHeaders {
req.setValue(value, forHTTPHeaderField: headerName)
Expand Down