From 7289c4b036d8a78c48f8c9e66ba998e6730e80d2 Mon Sep 17 00:00:00 2001 From: Josh Wong <26672964+yinkiu602@users.noreply.github.com> Date: Tue, 25 Jun 2024 06:42:03 +0800 Subject: [PATCH] Add credentials: include and Cookie header to prevent 401 error (#8600) * Add credentials: include and Cookie header to prevent 401 error * FIx formatting * add changeset --------- Co-authored-by: gradio-pr-bot --- .changeset/flat-results-divide.md | 6 ++++++ client/js/src/client.ts | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/flat-results-divide.md diff --git a/.changeset/flat-results-divide.md b/.changeset/flat-results-divide.md new file mode 100644 index 0000000000..ccfabf7137 --- /dev/null +++ b/.changeset/flat-results-divide.md @@ -0,0 +1,6 @@ +--- +"@gradio/client": minor +"gradio": minor +--- + +feat:Add credentials: include and Cookie header to prevent 401 error diff --git a/client/js/src/client.ts b/client/js/src/client.ts index 46d3affd6d..0ab3a5c876 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -67,9 +67,16 @@ export class Client { } stream(url: URL): EventSource { + const headers = new Headers(); + if (this && this.cookies) { + headers.append("Cookie", this.cookies); + } + this.abort_controller = new AbortController(); this.stream_instance = readable_stream(url.toString(), { + credentials: "include", + headers: headers, signal: this.abort_controller.signal });