expressを使うときにデフォルトのHTTPリクエストのタイムアウトが何であるか教えてもらえますか?Express.js HTTPリクエストのタイムアウト
これは、ブラウザーやサーバーが接続を手動で終了したときに、http/Nov.jsサーバーがHTTP要求を処理してから何秒後に接続を閉じるかということです。
このタイムアウトはどのように変更すればよいですか?私は特別なオーディオ変換ルートのために約15分に設定したいと思います。
ありがとうございます。
トム
expressを使うときにデフォルトのHTTPリクエストのタイムアウトが何であるか教えてもらえますか?Express.js HTTPリクエストのタイムアウト
これは、ブラウザーやサーバーが接続を手動で終了したときに、http/Nov.jsサーバーがHTTP要求を処理してから何秒後に接続を閉じるかということです。
このタイムアウトはどのように変更すればよいですか?私は特別なオーディオ変換ルートのために約15分に設定したいと思います。
ありがとうございます。
トム
req.connection.setTimeout(ms);
複数のリクエストを同じソケットで送信できるので、悪い考えです。
connect-timeoutを試すか、これを使用する:
var errors = require('./errors');
const DEFAULT_TIMEOUT = 10000;
const DEFAULT_UPLOAD_TIMEOUT = 2 * 60 * 1000;
/*
Throws an error after the specified request timeout elapses.
Options include:
- timeout
- uploadTimeout
- errorPrototype (the type of Error to throw)
*/
module.exports = function(options) {
//Set options
options = options || {};
if(options.timeout == null)
options.timeout = DEFAULT_TIMEOUT;
if(options.uploadTimeout == null)
options.uploadTimeout = DEFAULT_UPLOAD_TIMEOUT;
return function(req, res, next) {
//timeout is the timeout timeout for this request
var tid, timeout = req.is('multipart/form-data') ? options.uploadTimeout : options.timeout;
//Add setTimeout and clearTimeout functions
req.setTimeout = function(newTimeout) {
if(newTimeout != null)
timeout = newTimeout; //Reset the timeout for this request
req.clearTimeout();
tid = setTimeout(function() {
if(options.throwError && !res.finished)
{
//throw the error
var proto = options.error == null ? Error : options.error;
next(new proto("Timeout " + req.method + " " + req.url));
}
}, timeout);
};
req.clearTimeout = function() {
clearTimeout(tid);
};
req.getTimeout = function() {
return timeout;
};
//proxy end to clear the timeout
var oldEnd = res.end;
res.end = function() {
req.clearTimeout();
res.end = oldEnd;
return res.end.apply(res, arguments);
}
//start the timer
req.setTimeout();
next();
};
}
req.connection.setTimeout(ms);
Node.js.におけるHTTPサーバの要求タイムアウトを設定するように見えます
は、これが接続タイムアウトない要求のタイムアウトを設定します。 – kilianc
ありがとうございました。あなたの回答を受け入れられた回答に変更しました。 – Tom