Skip to content
This repository has been archived by the owner on Jul 12, 2018. It is now read-only.

allow extensible server #5

Closed
wants to merge 1 commit into from
Closed

allow extensible server #5

wants to merge 1 commit into from

Conversation

devsnek
Copy link

@devsnek devsnek commented Mar 15, 2018

No description provided.

@coveralls
Copy link

coveralls commented Mar 15, 2018

Pull Request Test Coverage Report for Build 33

  • 5 of 6 (83.33%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 59.944%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/index.js 5 6 83.33%
Files with Coverage Reduction New Missed Lines %
src/util.js 1 81.08%
Totals Coverage Status
Change from base Build 27: -0.2%
Covered Lines: 153
Relevant Lines: 232

💛 - Coveralls

Copy link
Owner

@hugmanrique hugmanrique left a comment

Choose a reason for hiding this comment

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

This project tries to follow the WebSocket standard as closely as possible, and rejecting connections when the client fails to follow the protocol must be done.

You can also add the server param to the decontruscted options object and default it to turbo.createServer

@devsnek
Copy link
Author

devsnek commented Mar 15, 2018

so this entire lib is effectively useless if you want to use it in tandem with regular http requests? you would have to put a reverse proxy in, run an http server and a ws server? websocket upgrade requests exist specifically for this reason 😕

also i don't think i can do server = turbo.createServer(opts, ...) because opts doesn't exist yet

@hugmanrique
Copy link
Owner

I hadn't thought about that scenario, thanks for the idea! Will create some tests and will merge if everything works as expected.

@jacktuck
Copy link

jacktuck commented Mar 16, 2018

I don't think there's a compelling reason to implement this. I suspect most people are looking for a fast websocket server from this library. Additionally, I've not seen any other websocket server allow this - but please share any that do :).

Is it not better to have separation of concerns and spin up a http server for http traffic - with, say, maybe turbo-http, if you like.

just my 2 cents <3

@devsnek
Copy link
Author

devsnek commented Mar 16, 2018

@jacktuck the most used websocket library for node, ws, not only allows this behavior but encourages it. the builtin node http library doesn't emit a request for upgrade requests but instead an upgrade event which the library hooks into, meaning you can transparently attach the websocket server to any http server. most people implementing a websocket server also need to serve regular http requests for webpages and stuff. this can be the fastest websocket library ever made but if its a pain to hook up with your webpage server no one will use it

@jacktuck
Copy link

@devsnek You're right, my bad.

return this.closeConnection(res, 400);
const headers = req.getAllHeaders();
if (/websocket/i.test(headers.get('Upgrade')) && /upgrade/i.test(headers.get('Connection'))) {
return this.handleUpgrade(req, res);
Copy link

Choose a reason for hiding this comment

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

@devsnek did you test this? From my understanding which may be wrong, this will handle stuff coming from turbo-http and in turn turbo-net. The socket provided by turbo-net is not compatible with the Node.js net.Socket so I think you can't simply use an external server, unless that server is a turbo-http server. Is this the goal? It's not clear from the title.

Copy link
Author

Choose a reason for hiding this comment

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

yes this only works with a turbo-http server instance

Copy link

Choose a reason for hiding this comment

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

Gotcha.

Copy link
Owner

Choose a reason for hiding this comment

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

Can you change those regex to String.prototype.includes()? Otherwise, I agree with @devsnek, because as long as you can attach event listeners and you follow the turbo-http API it should be fine.

Copy link
Author

Choose a reason for hiding this comment

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

regex test allowed the values to not be there or be weirdly cased. otherwise I have to make sure they are strings and such

Copy link

@jacktuck jacktuck Mar 17, 2018

Choose a reason for hiding this comment

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

if we have to worry about the string's case, i think the current solution is the fastest? https://jsperf.com/includes-vs-test/1

@devsnek devsnek closed this Apr 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants