mirror of
https://github.com/hexboy/maven-mirror-tool.git
synced 2025-09-01 01:59:15 +00:00
fix "Can't set headers after they are sent to the client" error
This commit is contained in:
parent
d22e677683
commit
93bbb45d48
2 changed files with 14 additions and 4 deletions
|
@ -79,10 +79,14 @@ export class GotDownloader {
|
||||||
.head(srv.url + url, this.getOptions(srv, 'head'))
|
.head(srv.url + url, this.getOptions(srv, 'head'))
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
res.set(r.headers);
|
res.set(r.headers);
|
||||||
res.sendStatus(r.statusCode);
|
if (!res.headersSent) {
|
||||||
|
res.sendStatus(r.statusCode);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((r: { statusCode?: number }) => {
|
.catch((r: { statusCode?: number }) => {
|
||||||
res.sendStatus(r?.statusCode ?? 404);
|
if (!res.headersSent) {
|
||||||
|
res.sendStatus(r?.statusCode ?? 404);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
10
src/index.ts
10
src/index.ts
|
@ -57,10 +57,16 @@ const cacheRequestHandler: RequestHandler = (req, res, next) => {
|
||||||
downloader.download(url, srv, res);
|
downloader.download(url, srv, res);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res.sendStatus(403);
|
if (!res.headersSent) {
|
||||||
|
res.sendStatus(403);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => res.sendStatus(403));
|
.catch(() => {
|
||||||
|
if (!res.headersSent) {
|
||||||
|
res.sendStatus(403);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// init cache dir
|
// init cache dir
|
||||||
|
|
Loading…
Add table
Reference in a new issue