mirror of
https://github.com/hexboy/maven-mirror-tool.git
synced 2025-04-22 14:39:09 +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'))
|
||||
.then((r) => {
|
||||
res.set(r.headers);
|
||||
res.sendStatus(r.statusCode);
|
||||
if (!res.headersSent) {
|
||||
res.sendStatus(r.statusCode);
|
||||
}
|
||||
})
|
||||
.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);
|
||||
}
|
||||
} else {
|
||||
res.sendStatus(403);
|
||||
if (!res.headersSent) {
|
||||
res.sendStatus(403);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(() => res.sendStatus(403));
|
||||
.catch(() => {
|
||||
if (!res.headersSent) {
|
||||
res.sendStatus(403);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// init cache dir
|
||||
|
|
Loading…
Add table
Reference in a new issue