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

force ws:// protocol when instantiating a new WebSocket #172

Conversation

leorossi
Copy link
Contributor

ws@8.0.0 introduces a breaking change that throws a SyntaxError when calling new WebSocket() with an URL with http:// protocol.
This PR fixes such issue, forcing when needed the ws:// protocol instead.

Checklist

Copy link

@simoneb simoneb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work with SSL?

@leorossi
Copy link
Contributor Author

does this work with SSL?

yes, I have updated the code

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you bump ws as well?

test/ws-prefix-rewrite-core.js Outdated Show resolved Hide resolved
test/utils.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@leorossi
Copy link
Contributor Author

leorossi commented Aug 2, 2021

Could you bump ws as well?

ws is already bumped target branch from dependabot

@@ -1,7 +1,7 @@
'use strict'
const From = require('fastify-reply-from')
const WebSocket = require('ws')

const { convertUrlToWebSocket } = require('./utils')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: keep a blank line between requires/imports and other statements

@@ -0,0 +1,8 @@
'use strict'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep a blank line below this

async function proxyServer (t, backendURL, backendPath, proxyOptions, wrapperOptions) {
async function proxyServer(t, backendURL, backendPath, proxyOptions, wrapperOptions) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid these formatting changes? they're inconsistent with the rest of the codebase, e.g. here. Either we change it everywhere or we don't change it. I would go with the latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My linter was messed up, now it should be fixed to the previous version (with space)

const t = require('tap')
const { convertUrlToWebSocket } = require('../utils')

t.test('convertUrlToWebSocket', function (t) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tap has a built-in way to create array of tests, check it out. also, before and after are not two very meaningful names for inputs and outputs of the tests. more idiomatic names are e.g. input/expected

Copy link

@simoneb simoneb Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out I was wrong!

test/ws-prefix-rewrite-core.js Outdated Show resolved Hide resolved
utils.js Outdated Show resolved Hide resolved
@leorossi leorossi requested a review from mcollina August 2, 2021 15:13
@simoneb
Copy link

simoneb commented Aug 2, 2021

If we're happy with this let's merge it into the base branch which is the dependabot bump PR.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit e21fb0e into fastify:dependabot/npm_and_yarn/ws-8.0.0 Aug 3, 2021
dependabot-merge-action bot pushed a commit that referenced this pull request Aug 3, 2021
* Bump ws from 7.5.3 to 8.0.0

Bumps [ws](https://github.com/websockets/ws) from 7.5.3 to 8.0.0.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](websockets/ws@7.5.3...8.0.0)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* force `ws://` protocol when instantiating a new `WebSocket` (#172)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Leonardo Rossi <leonardo.rossi@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants