Skip to content

Commit

Permalink
[proposal] Make headers call for AgentRestClient dynamic
Browse files Browse the repository at this point in the history
Fixes decentralized-identity#1313

Signed-off-by: Mirko Mollik <mirko.mollik@fit.fraunhofer.de>
  • Loading branch information
cre8 committed Jan 16, 2024
1 parent ac1b620 commit 817080c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/remote-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ export class AgentRestClient implements IAgentPlugin {
url: string
enabledMethods: string[]
schema?: IAgentPluginSchema
headers?: Record<string, string>
headers?: Record<string, string> | (() => Record<string, string>)
}) {
this.url = options.url
this.schema = options.schema

for (const method of options.enabledMethods) {
this.methods[method] = async (args: any) => {
// in case headers is an async call, we will wait for it to resolve
const headers = typeof options.headers === 'function' ? await options.headers() : options.headers
const res = await fetch(this.url + '/' + method, {
headers: { ...options.headers, 'Content-Type': 'application/json' },
headers: { ...headers, 'Content-Type': 'application/json' },
method: 'post',
body: JSON.stringify(args),
})
Expand Down

0 comments on commit 817080c

Please sign in to comment.