Merge pull request #152 from lbryio/authHeaders
adds headers and means to set and unset them to Lbry api calls
This commit is contained in:
commit
03998a2acf
5 changed files with 29 additions and 1 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
|
# Jetbrains
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
|
9
dist/bundle.es.js
vendored
9
dist/bundle.es.js
vendored
|
@ -606,12 +606,20 @@ const Lbry = {
|
||||||
isConnected: false,
|
isConnected: false,
|
||||||
connectPromise: null,
|
connectPromise: null,
|
||||||
daemonConnectionString: 'http://localhost:5279',
|
daemonConnectionString: 'http://localhost:5279',
|
||||||
|
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
|
||||||
|
|
||||||
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
|
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
|
||||||
setDaemonConnectionString: value => {
|
setDaemonConnectionString: value => {
|
||||||
Lbry.daemonConnectionString = value;
|
Lbry.daemonConnectionString = value;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setApiHeader: (key, value) => {
|
||||||
|
Lbry.apiRequestHeaders = Object.assign(Lbry.apiRequestHeaders, { [key]: value });
|
||||||
|
},
|
||||||
|
|
||||||
|
unsetApiHeader: key => {
|
||||||
|
Object.keys(Lbry.apiRequestHeaders).includes(key) && delete Lbry.apiRequestHeaders['key'];
|
||||||
|
},
|
||||||
// Allow overriding Lbry methods
|
// Allow overriding Lbry methods
|
||||||
overrides: {},
|
overrides: {},
|
||||||
setOverride: (methodName, newMethod) => {
|
setOverride: (methodName, newMethod) => {
|
||||||
|
@ -730,6 +738,7 @@ function apiCall(method, params, resolve, reject) {
|
||||||
const counter = new Date().getTime();
|
const counter = new Date().getTime();
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: Lbry.apiRequestHeaders,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method,
|
method,
|
||||||
|
|
3
dist/flow-typed/Lbry.js
vendored
3
dist/flow-typed/Lbry.js
vendored
|
@ -153,7 +153,10 @@ declare type LbryTypes = {
|
||||||
connectPromise: ?Promise<any>,
|
connectPromise: ?Promise<any>,
|
||||||
connect: () => void,
|
connect: () => void,
|
||||||
daemonConnectionString: string,
|
daemonConnectionString: string,
|
||||||
|
apiRequestHeaders: {[key: string]: string},
|
||||||
setDaemonConnectionString: string => void,
|
setDaemonConnectionString: string => void,
|
||||||
|
setApiHeader: (string, string) => void,
|
||||||
|
unsetApiHeader: (string) => void,
|
||||||
overrides: { [string]: ?Function },
|
overrides: { [string]: ?Function },
|
||||||
setOverride: (string, Function) => void,
|
setOverride: (string, Function) => void,
|
||||||
getMediaType: (string, ?string) => string,
|
getMediaType: (string, ?string) => string,
|
||||||
|
|
3
flow-typed/Lbry.js
vendored
3
flow-typed/Lbry.js
vendored
|
@ -153,7 +153,10 @@ declare type LbryTypes = {
|
||||||
connectPromise: ?Promise<any>,
|
connectPromise: ?Promise<any>,
|
||||||
connect: () => void,
|
connect: () => void,
|
||||||
daemonConnectionString: string,
|
daemonConnectionString: string,
|
||||||
|
apiRequestHeaders: {[key: string]: string},
|
||||||
setDaemonConnectionString: string => void,
|
setDaemonConnectionString: string => void,
|
||||||
|
setApiHeader: (string, string) => void,
|
||||||
|
unsetApiHeader: (string) => void,
|
||||||
overrides: { [string]: ?Function },
|
overrides: { [string]: ?Function },
|
||||||
setOverride: (string, Function) => void,
|
setOverride: (string, Function) => void,
|
||||||
getMediaType: (string, ?string) => string,
|
getMediaType: (string, ?string) => string,
|
||||||
|
|
|
@ -11,12 +11,20 @@ const Lbry: LbryTypes = {
|
||||||
isConnected: false,
|
isConnected: false,
|
||||||
connectPromise: null,
|
connectPromise: null,
|
||||||
daemonConnectionString: 'http://localhost:5279',
|
daemonConnectionString: 'http://localhost:5279',
|
||||||
|
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
|
||||||
|
|
||||||
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
|
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
|
||||||
setDaemonConnectionString: (value: string) => {
|
setDaemonConnectionString: (value: string) => {
|
||||||
Lbry.daemonConnectionString = value;
|
Lbry.daemonConnectionString = value;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setApiHeader: (key: string, value: string) => {
|
||||||
|
Lbry.apiRequestHeaders = Object.assign(Lbry.apiRequestHeaders, { [key]: value });
|
||||||
|
},
|
||||||
|
|
||||||
|
unsetApiHeader: key => {
|
||||||
|
Object.keys(Lbry.apiRequestHeaders).includes(key) && delete Lbry.apiRequestHeaders['key'];
|
||||||
|
},
|
||||||
// Allow overriding Lbry methods
|
// Allow overriding Lbry methods
|
||||||
overrides: {},
|
overrides: {},
|
||||||
setOverride: (methodName, newMethod) => {
|
setOverride: (methodName, newMethod) => {
|
||||||
|
@ -141,6 +149,7 @@ function apiCall(method: string, params: ?{}, resolve: Function, reject: Functio
|
||||||
const counter = new Date().getTime();
|
const counter = new Date().getTime();
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: Lbry.apiRequestHeaders,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method,
|
method,
|
||||||
|
|
Loading…
Reference in a new issue