jishi/node-sonos-discovery

HTTPS Support in lib/helpers/request.js

Closed this issue · 5 comments

Kudos everyone for the great work here and the consuming project node-sonos-http-api.

I'm writing this issue in the node-sonos-discovery as I believe this is the source of the error although I'm using this library from an instance of node-sonos-http-api.

I've been having issues with the webhook out of the box when I point to a HTTPS endpoint. Specifically, I'm receiving a HTTP Status Code of 400 and looking at the URL parsed values, path, method, and host look good. I did specify the port 443 in the settings.webhook (node-sonos-http-api) to help it along but no luck. (Details below)

Given, the webhook URI as: https://api.YOURDOMAIN.com:443/api/webhook, the errors below are generated:

Error stack from node-sonos-http-api (sonos-http.api.js > invokewebhook()) but originating in sonos-discovery

{ Error
at invokeWebhook (/usr/src/app/lib/sonos-http-api.js:125:5)
at SonosSystem. (/usr/src/app/lib/sonos-http-api.js:36:5)
at emitOne (events.js:96:13)
at SonosSystem.emit (events.js:188:7)
at NotificationListener.notificationHandler (/usr/src/app/node_modules/sonos-discovery/lib/models/Player.js:323:20)
at emitTwo (events.js:111:20)
at NotificationListener.emit (events.js:191:7)
at parseLastChange.then (/usr/src/app/node_modules/sonos-discovery/lib/NotificationListener.js:125:17)
at process._tickCallback (internal/process/next_tick.js:103:7)
method: 'POST',
path: '/api/webhook',
host: 'api.YOURDOMAIN.com',
port: 443,
headers: { 'Content-Type': 'application/json', 'Content-Length': 127 },
statusCode: 400 }
2016-11-18T21:04:44.139Z ERROR Could not reach webhook endpoint https://api.YOURDOMAIN.com:443/api/webhook for some reason. Verify that the receiving end is up and running.

Checking the node-sonos-discovery/lib/helpers/request.js, I see the HTTP library is used and I'm wondering if the HTTPS library can be used for secure connections. I'm pretty new to NodeJS and the existing libraries so pardon my ignorance if I'm over simplifying. If this is an isolated need, no problem, I can fork the project for my own needs, just let me know.

Current version (not the latest, but no significant changes that I can see):
sonos-discovery (v1.1.4)
sonos-http-api (v1.1.5)

Thanks!
~Basil

jishi commented

Nice observation. When I initially did the request.js helper (to avoid unecessary dependencies on large external libraries) it was primarily for communicating with the Sonos players, which is done over HTTP only.

Supporting https is fairly trivial, basically use the https module instead of http if url scheme is https. I'll try and fix it during the weekend.

Thanks Jimmy! As always, you're extremely responsive and knowledgeable. Let me know if there's anything I can do, I'll have some intermittent availability this weekend but I can definitely test early next week.

jishi commented

Resolved this with v1.1.8, updated http-api accordingly.

jishi commented

This wasn't fixed at all, my testing was not sufficient.

jishi commented

Now it should be fixed! Probably worked if you specified port in the url, but not if you omitted it.