Skip to content

Commit a3e5025

Browse files
committed
Supports basic auth in remote versions
1 parent 2bfce0d commit a3e5025

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/app/api/proxy/route.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,20 @@ async function downloadFile(params: {
5555
const { url, maxBytes, timeoutInSeconds } = params
5656
const abortController = new AbortController()
5757
const timeoutSignal = AbortSignal.timeout(timeoutInSeconds * 1000)
58-
const response = await fetch(url, {
58+
let headers: {[key: string]: string} = {}
59+
// Extract basic auth from URL and construct an Authorization header instead.
60+
if ((url.username && url.username.length > 0) || (url.password && url.password.length > 0)) {
61+
const username = decodeURIComponent(url.username)
62+
const password = decodeURIComponent(url.password)
63+
headers["Authorization"] = "Basic " + btoa(`${username}:${password}`)
64+
}
65+
// Make sure basic auth is removed from URL.
66+
const urlWithoutAuth = url
67+
urlWithoutAuth.username = ""
68+
urlWithoutAuth.password = ""
69+
const response = await fetch(urlWithoutAuth, {
70+
method: "GET",
71+
headers,
5972
signal: AbortSignal.any([abortController.signal, timeoutSignal])
6073
})
6174
if (!response.body) {

0 commit comments

Comments
 (0)