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 <abubakar@huggingface.co>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
This commit is contained in:
gianlucaelia 2024-11-15 21:05:45 +01:00 committed by GitHub
parent 75ad3e3419
commit eae345e5fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/client": minor
"gradio": minor
---
feat:Allow settings custom headers in js client

View File

@ -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();

View File

@ -299,6 +299,7 @@ export interface ClientOptions {
auth?: [string, string] | null;
with_null_state?: boolean;
events?: EventType[];
headers?: Record<string, string>;
}
export interface FileData {