Leanplum / Leanplum-iOS-SDK

Leanplum's integrated solution delivers meaningful engagement across messaging and the in-app experience.
https://www.leanplum.com
Apache License 2.0
71 stars 59 forks source link

DevServer connection fix - Improve sockets handshake response check #577

Closed nzagorchev closed 3 months ago

nzagorchev commented 3 months ago
What Where/Who
People Involved @nzagorchev

Background

The socket connection to the DevServer started failing. The server error is websocket connection invalid which results in error WebSocketErrorDomain error 2 in the SDK. The errors are caused by changes/rewriting to the request headers and the response.

  1. The server expects Upgrade: WebSocket but receives Upgrade: websocket (The SDK does send Upgrade: WebSocket). This is fixed on the server.
  2. The SDK expects a specific response and headers (direct comparison) but receives:
    HTTP/1.1 101 Switching Protocols
    WebSocket-Origin: http://dev-staging.leanplum.com/
    WebSocket-Location: ws://dev-staging.leanplum.com/socket.io/1/websocket/DDeRoYTza-zUWMyDHIio
    Date: Wed, 24 Jan 2024 11:04:28 GMT
    Via: 1.1 google
    Upgrade: websocket
    Connection: Upgrade

Implementation

Change the check for successful handshake. Parse the response and validate the status code, Upgrade and Connection headers.

Testing steps

Manual testing the dev server connection. Unit tests.

Is this change backwards-compatible?

Yes