From eae345e5fde39aea220b57c6a954cd7d72ff32d5 Mon Sep 17 00:00:00 2001 From: gianlucaelia Date: Fri, 15 Nov 2024 21:05:45 +0100 Subject: [PATCH] Allow settings custom headers in js client (#9930) * Allow settings custom headers in js client * add changeset * get_jwt doesn't need additional headers * format --------- Co-authored-by: Abubakar Abid Co-authored-by: gradio-pr-bot Co-authored-by: Hannah --- .changeset/smart-houses-deny.md | 6 ++++++ client/js/src/client.ts | 10 ++++++++++ client/js/src/types.ts | 1 + 3 files changed, 17 insertions(+) create mode 100644 .changeset/smart-houses-deny.md diff --git a/.changeset/smart-houses-deny.md b/.changeset/smart-houses-deny.md new file mode 100644 index 0000000000..a0137d74bd --- /dev/null +++ b/.changeset/smart-houses-deny.md @@ -0,0 +1,6 @@ +--- +"@gradio/client": minor +"gradio": minor +--- + +feat:Allow settings custom headers in js client diff --git a/client/js/src/client.ts b/client/js/src/client.ts index 47058adb75..aef0684d83 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -70,6 +70,11 @@ export class Client { if (this && this.cookies) { headers.append("Cookie", this.cookies); } + if (this && this.options.headers) { + for (const name in this.options.headers) { + headers.append(name, this.options.headers[name]); + } + } return fetch(input, { ...init, headers }); } @@ -79,6 +84,11 @@ export class Client { if (this && this.cookies) { headers.append("Cookie", this.cookies); } + if (this && this.options.headers) { + for (const name in this.options.headers) { + headers.append(name, this.options.headers[name]); + } + } this.abort_controller = new AbortController(); diff --git a/client/js/src/types.ts b/client/js/src/types.ts index fa7d5c7f19..84baddf2ba 100644 --- a/client/js/src/types.ts +++ b/client/js/src/types.ts @@ -299,6 +299,7 @@ export interface ClientOptions { auth?: [string, string] | null; with_null_state?: boolean; events?: EventType[]; + headers?: Record; } export interface FileData {