Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/app/api/proxy/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ async function downloadFile(params: {
const { url, maxBytes, timeoutInSeconds } = params
const abortController = new AbortController()
const timeoutSignal = AbortSignal.timeout(timeoutInSeconds * 1000)
const response = await fetch(url, {
let headers: {[key: string]: string} = {}
// Extract basic auth from URL and construct an Authorization header instead.
if ((url.username && url.username.length > 0) || (url.password && url.password.length > 0)) {
const username = decodeURIComponent(url.username)
const password = decodeURIComponent(url.password)
headers["Authorization"] = "Basic " + btoa(`${username}:${password}`)
}
// Make sure basic auth is removed from URL.
const urlWithoutAuth = url
urlWithoutAuth.username = ""
urlWithoutAuth.password = ""
const response = await fetch(urlWithoutAuth, {
method: "GET",
headers,
signal: AbortSignal.any([abortController.signal, timeoutSignal])
})
if (!response.body) {
Expand Down
Loading