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

SocketIOClientOption.cookies ignored in Starscream with HTTPCookieStorage #1449

Open
Jman012 opened this issue Aug 14, 2023 · 1 comment
Open

Comments

@Jman012
Copy link

Jman012 commented Aug 14, 2023

The SocketIOClientOption.cookies configuration option is sometimes ignored entirely, if any cookie exists in the HTTPCookieStorage.shared.cookies(for: url) for the installed Swift application.

See https://github.com/daltoniam/Starscream/blob/4.0.4/Sources/Framer/HTTPHandler.swift#L70

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

The code will overwrite whatever cookies are attempted to be set by this library. This caused a lot of confusion because when debugging an issue, it looked like down to the Engine.IO layer that the configured cookies were being set properly. But it was in the Starscream layer that they were ignored.

It doesn't look like there's a solution other than to document this behavior more clearly to avoid confusion and bugs in the future. Starscream doesn't look like it allows custom cookies if any HTTPCookieStorage cookies exist.

@Jman012
Copy link
Author

Jman012 commented Aug 14, 2023

This happened to occur with something like the following SocketManager configuration:

socketManager = SocketManager(
	socketURL: URL(string: "wss://example.com")!,
	config: [
		.log(true),
		.compress,
		.forceWebsockets(true),
		.extraHeaders([
			"Host": "example.com",
			"Origin": "https://example.com",
		]),
		.cookies([
			HTTPCookie(properties: [
				.domain: ".example.com",
				.path: "/",
				.name: "sid",
				.value: sidValue,
				.secure: "Secure",
				.expires: NSDate(timeIntervalSinceNow: 1_000_000_000),
			])!,
		]),
		.reconnects(false),
		.secure(true),
		.path("/"),
		.connectParams([
			"__sails_io_sdk_version": "0.13.8",
			"__sails_io_sdk_platform": "tvos",
			"__sails_io_sdk_language": "swift",
		]),
		.version(.two),
	])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant