Skip to content

How to set a custom URL #376

@Siretfel

Description

@Siretfel

Hello I am quite new to this topic, so please excuse me in advance if the questions is "simple" or naive.

In order to connect to the "web socket" I first send a POST request and I am saving a "cookie". With the cookie save we are ready to upgrade to ws. I am doing like this:

func establishConnection(cookie: [NSHTTPCookie]) {

    let originalString : String = "/my-server/ws?topic=Products"
    let escapedAddress : String = originalString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!

    socket = SocketIOClient(socketURL: NSURL(string: "http://151.197.24.33:5555")!, options: [
        "reconnects": false,
        "reconnectAttempts": 1,
        "reconnectWait": 10,
        "log":true,
        "voipEnabled": true,
        "extraHeaders": ["Connection": "Upgrade", "Upgrade": "websocket""],
        "path": escapedAddress,
        "cookie": cookie
    ])

    socket!.connect()


}

I am capturing data with tcpdump and I saw that the URL that is being sent is:

http://151.197.24.33:55551/my-server/ws%3Ftopic=Product?transport=polling&b64=1

So I have two problems. The first is that the URL is not encoded and that is why "ws%3F" is show instead of "ws?" and second ?"transport=polling" is also sent that confuses the server and sents 404.

How do we resolve both issues?

In the SocketEngine.swift I did this (for testing purposes)
urlWebSocket.percentEncodedQuery = "" + queryString
urlPolling.percentEncodedQuery = "" + queryString

and changing the queryString variable in the same file create the correct URL, however I cannot connect since the "Connection: Upgrade" is not sent. The http header contains "Connection: keep-alive".

Can you please advice? When I sent the request via "curl" seems to have better results, ie I am taking a 426 from the server

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions