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

verifyClient callback now accepts "headers" parameter #1379

Merged
merged 2 commits into from May 12, 2018

Conversation

Jokero
Copy link
Contributor

@Jokero Jokero commented May 10, 2018

Which is passed to abortHandshake().

Fixes: #695
Fixes: #728

.gitignore Outdated
@@ -2,4 +2,8 @@ node_modules/
.nyc_output/
coverage/
.vscode/
.idea/
Copy link
Member

Choose a reason for hiding this comment

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

Can you please remove these? Not sure how .vscode ended here, but I think these should be in the global gitignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just .idea/?

Copy link
Member

Choose a reason for hiding this comment

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

No, also the others. I would prefer this file to be unchanged.

doc/ws.md Outdated
@@ -49,10 +49,12 @@ if `verifyClient` is provided with two arguments then those are:
- `cb` {Function} A callback that must be called by the user upon inspection
of the `info` fields. Arguments in this callback are:
- `result` {Boolean} Whether or not to accept the handshake.
- `code` {Number} When `result` is `false` this field determines the HTTP
- `[code]` {Number} When `result` is `false` this field determines the HTTP
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the optional syntax, it's not used in the docs. We can specify that it defaults to 401, if wanted.

doc/ws.md Outdated
reason phrase.
- `[headers]` {Object} When `result` is `false` this field determines additional HTTP
headers to be sent to the client (for example, `{ 'Set-Cookie': 'abortReason=tooManyConnections' }`).
Copy link
Member

Choose a reason for hiding this comment

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

Remove () and put the example on a new line:

"... the client. For example,"

this.options.verifyClient(info, (verified, code, message) => {
if (!verified) return abortHandshake(socket, code || 401, message);
this.options.verifyClient(info, (verified, code, message, headers) => {
if (!verified) return abortHandshake(socket, code || 401, message, headers);
Copy link
Member

Choose a reason for hiding this comment

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

Can we try to keep the limit of 80 chars per line?

if (socket.writable) {
message = message || http.STATUS_CODES[code];
headers = Object.assign({}, {
Copy link
Member

@lpinca lpinca May 11, 2018

Choose a reason for hiding this comment

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

The first {} is not needed. I also wonder if it's better to move the defaults after the custom headers to prevent them from being overridden.

Edit: Overriding defaults should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also thought about moving custom headers before common. But decided to have common headers before in order to have them at the top of response (although order of headers is not important)

'Content-type: text/html\r\n' +
`Content-Length: ${Buffer.byteLength(message)}\r\n` +
'\r\n' +
Object.keys(headers).map(header => `${header}: ${headers[header]}`).join('\r\n') +
Copy link
Member

Choose a reason for hiding this comment

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

80 chars pls and same below in the test.

@lpinca
Copy link
Member

lpinca commented May 11, 2018

Left a few comments but overall LGTM.

@Jokero
Copy link
Contributor Author

Jokero commented May 11, 2018

Few 😄 Fixed. Take a look please

@lpinca
Copy link
Member

lpinca commented May 11, 2018

Thanks, will merge later.

@lpinca lpinca merged commit d871bdf into websockets:master May 12, 2018
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

2 participants