Commit bc6e4dfe authored by Rafał Miłecki's avatar Rafał Miłecki
Browse files

luci-base: use actual JSON-RPC for verifying ubus RPC URL



Sending GET request to the main RPC base URL and expecting HTTP response
code 400 had two flaws:
1. It was not verifying actual JSON-RPC interface availability
2. It did not allow implementing support for new requests

Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
Acked-by: default avatarJo-Philipp Wich <jo@mein.io>
parent 5ca32844
...@@ -2553,10 +2553,16 @@ ...@@ -2553,10 +2553,16 @@
rpcBaseURL = Session.getLocalData('rpcBaseURL'); rpcBaseURL = Session.getLocalData('rpcBaseURL');
if (rpcBaseURL == null) { if (rpcBaseURL == null) {
var msg = {
jsonrpc: '2.0',
id: 'init',
method: 'list',
params: undefined
};
var rpcFallbackURL = this.url('admin/ubus'); var rpcFallbackURL = this.url('admin/ubus');
rpcBaseURL = Request.get(env.ubuspath).then(function(res) { rpcBaseURL = Request.post(env.ubuspath, msg, { nobatch: true }).then(function(res) {
return (rpcBaseURL = (res.status == 400) ? env.ubuspath : rpcFallbackURL); return (rpcBaseURL = res.status == 200 ? env.ubuspath : rpcFallbackURL);
}, function() { }, function() {
return (rpcBaseURL = rpcFallbackURL); return (rpcBaseURL = rpcFallbackURL);
}).then(function(url) { }).then(function(url) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment