Returned Rest response URL does not include port number
Hi,
The following is the log of remoteopenhab binding. As you can see, the replied rest response's url reference truncate port number. This could be a problem if openhabcloud private instance doesn't use standard port.
14:53:52.951 [OH-safeCall-1] DEBUG o.o.b.r.i.h.RemoteopenhabBridgeHandler:127 - Initializing remote openHAB handler for bridge remoteopenhab:server:oh 14:53:52.954 [OH-safeCall-1] DEBUG o.o.b.r.i.h.RemoteopenhabBridgeHandler:153 - REST URL = https://myopenhab.org:443/rest/ 14:53:52.957 [-thingHandler-1] DEBUG o.o.b.r.i.h.RemoteopenhabBridgeHandler:334 - Try the root REST API... 14:53:52.963 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:521 - Request GET https://myopenhab.org/rest/ (provided url https://myopenhab.org:443/rest/ 14:53:53.707 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:153 - REST API version = 4 14:53:53.708 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:158 - REST API items = https://myopenhab.org/rest/items 14:53:53.708 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:159 - REST API things = https://myopenhab.org/rest/things 14:53:53.708 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:160 - REST API events = https://myopenhab.org/rest/events
I found the culprit. Please review this line and possible replace it with X-Forward-Host in routes/index.js line 380. This line may cause issue if the openhabcloud's serving port is not on standard HTTP/80 and HTTPS/443 ports
var requestId = this.requestTracker.acquireRequestId();
// make a local copy of request headers to modify
var requestHeaders = req.headers;
// We need to remove and modify some headers here
delete requestHeaders['cookie'];
delete requestHeaders['cookie2'];
delete requestHeaders['authorization'];
delete requestHeaders['x-real-ip'];
delete requestHeaders['x-forwarded-for'];
delete requestHeaders['x-forwarded-proto'];
delete requestHeaders['connection'];
requestHeaders['host'] = /*req.headers["host"]*/ req.headers["x-forwarded-host"] || system.getHost() + ':' + system.getPort();
requestHeaders['user-agent'] = 'openhab-cloud/0.0.1';
https://github.com/openhab/openhab-cloud/pull/331
I found the culprit. Please review this line and possible replace it with X-Forward-Host in routes/index.js line 380. This line may cause issue if the openhabcloud's serving port is not on standard HTTP/80 and HTTPS/443 ports
var requestId = this.requestTracker.acquireRequestId(); // make a local copy of request headers to modify var requestHeaders = req.headers; // We need to remove and modify some headers here delete requestHeaders['cookie']; delete requestHeaders['cookie2']; delete requestHeaders['authorization']; delete requestHeaders['x-real-ip']; delete requestHeaders['x-forwarded-for']; delete requestHeaders['x-forwarded-proto']; delete requestHeaders['connection']; requestHeaders['host'] = /*req.headers["host"]*/ req.headers["x-forwarded-host"] || system.getHost() + ':' + system.getPort(); requestHeaders['user-agent'] = 'openhab-cloud/0.0.1';
This is not good solution. When I tried, URL is changed to url of OH3 destination port instead of client using port. I use: OH3 tcp/8443, openhabcloud tcp/3000, nginx-proxy tcp/9443 and rest query to 9443 returns urls with 8443