From 1faf9bf542fc49f00a8d9e40877ef4ef0dbf1fdc Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 10 Jul 2018 10:41:26 -0300 Subject: [PATCH] Allow x-instance-id and X-Instance-ID header (#354) @RocketChat/ReactNative Closes #137 Some server configurations may send x-instance-id header with different case. --- app/lib/rocketchat.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index a20ef73f..c990626e 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -80,28 +80,21 @@ const RocketChat = { console.warn(`AsyncStorage error: ${ error.message }`); } }, + _hasInstanceId(headers) { + return (headers['x-instance-id'] != null && headers['x-instance-id'].length > 0) || (headers['X-Instance-ID'] != null && headers['X-Instance-ID'].length > 0); + }, async testServer(url) { if (/^(https?:\/\/)?(((\w|[0-9-_])+(\.(\w|[0-9-_])+)+)|localhost)(:\d+)?$/.test(url)) { try { let response = await RNFetchBlob.fetch('HEAD', url); response = response.respInfo; - if (response.status === 200 && response.headers['x-instance-id'] != null && response.headers['x-instance-id'].length) { + if (response.status === 200 && RocketChat._hasInstanceId(response.headers)) { return url; } } catch (e) { log('testServer', e); } } - // if (/^(https?:\/\/)?(((\w|[0-9-_])+(\.(\w|[0-9-_])+)+)|localhost)(:\d+)?$/.test(url)) { - // try { - // const response = await fetch(url, { method: 'HEAD' }); - // if (response.status === 200 && response.headers.get('x-instance-id') != null && response.headers.get('x-instance-id').length) { - // return url; - // } - // } catch (error) { - // console.log(error) - // } - // } throw new Error({ error: 'invalid server' }); }, _setUser(ddpMessage) {