Starscream icon indicating copy to clipboard operation
Starscream copied to clipboard

Bug fix with cookie on iOS 12

Open romanleshukov opened this issue 4 years ago • 2 comments

Hi,

We have found that HTTPCookieStorage.shared.cookies(for: url) in HTTPHandler.createUpgrade returns nil in case of wss scheme for iOS 12 (works fine for iOS 13+). So we think that

if let cookies = HTTPCookieStorage.shared.cookies(for: httpUrl ?? url), !cookies.isEmpty {
	let headers = HTTPCookie.requestHeaderFields(with: cookies)
	for (key, val) in headers {
		req.setValue(val, forHTTPHeaderField: key)
	}
}

should be changed to:

let scheme = (url.scheme == "ws" ? "http" : (url.scheme == "wss" ? "https" : url.scheme)) ?? ""
let httpUrl = URL(string: scheme + "://" + (url.host ?? "") + url.path)
if let cookies = HTTPCookieStorage.shared.cookies(for: httpUrl ?? url), !cookies.isEmpty {
	let headers = HTTPCookie.requestHeaderFields(with: cookies)
	for (key, val) in headers {
		req.setValue(val, forHTTPHeaderField: key)
	}
}

It looks like a workaround, but seems to work for all versions.

romanleshukov avatar Nov 20 '20 13:11 romanleshukov

Any updates for this issue?

distivi avatar Feb 05 '21 09:02 distivi

Is there any reply?

lexon avatar Feb 05 '21 09:02 lexon