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

Function to get socket host is removing www #5606

Open
2 tasks done
icmaia90 opened this issue Jan 15, 2025 · 2 comments
Open
2 tasks done

Function to get socket host is removing www #5606

icmaia90 opened this issue Jan 15, 2025 · 2 comments
Labels

Comments

@icmaia90
Copy link

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

No response

Steps to reproduce

Regarding the way websockets work for 3rd-party providers, there is a function called getSocketHost used in the companion-client to get the hostname to start the websocket connection.

The getSocketHost does not consider a full domain starting with www to generate the hostname. This behaviour may create a bug on domains that use page redirection for root domains.

Considering the Companion server is hosted in the URL https://www.example.com/companion
Considering there is a DNS page redirection that redirects every example.com to www.example.com

So the frontend Uppy application (through RequestClient) will try to create a websocket connection to: wss://example.com/companion/api/123456

Expected behavior

The RequestClient should be able to create the ws URL to wss://www.example.com/companion/api/123456

Actual behavior

The RequestClient creates the ws URL to wss://example.com/companion/api/123456

Considering the DNS rule to redirect root domain to full domain (with the www), the ws attempt connection will fail as DNS will reply with 3xx redirection while the request was expecting for 101 Switching Protocols to establish the ws connection

@icmaia90 icmaia90 added the Bug label Jan 15, 2025
@Murderlon
Copy link
Member

Hi, if you know you have a redirect setup why wouldn't you pass just pass the correct URL which doesn't require a redirect as your companionUrl?

@icmaia90
Copy link
Author

@Murderlon I'm not sure if I fully understand you.

As stated, the companionUrl is https://www.example.com/companion.
The getSocketHost function removes the www from the URL to create the socket URL. Check the Regex and how it extracts the host from the companionUrl: https://github.com/transloadit/uppy/blob/main/packages/%40uppy/utils/src/getSocketHost.ts
So, the URL created in RequestClient becomes wss://example.com/companion/api/123456. I do not have control over how the websocket URL is created

RequestClient getting the host from companionUrl: https://github.com/transloadit/uppy/blob/main/packages/%40uppy/companion-client/src/RequestClient.ts#L382
RequestClient creating the websocket from the previously defined host: https://github.com/transloadit/uppy/blob/main/packages/%40uppy/companion-client/src/RequestClient.ts#L448

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

No branches or pull requests

2 participants