本文整理匯總了TypeScript中@jonggrang/http-types.formatHttpDate函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript formatHttpDate函數的具體用法?TypeScript formatHttpDate怎麽用?TypeScript formatHttpDate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了formatHttpDate函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: FileInfo
.chain(stat => {
if (stat.isFile()) {
let time = H.fromDate(stat.mtime);
let date = H.formatHttpDate(time);
return T.pure(new FileInfo(path, stat.size, time, date));
}
return T.raise(new Error(`getInfo: ${path} isn't a file`));
});
示例2: serveFile
export function serveFile(ss: StaticSettings, req: IncomingMessage, file: File): T.Task<StaticResponse> {
const mLastSent = ifMofiedSince_(req.headers);
const mdate = P.mapMaybe(file.getModified, H.fromDate);
function respond(headers: H.ResponseHeaders): T.Task<StaticResponse> {
return T.pure({
file,
headers: cacheControl(ss.maxAge, headers),
tag: StaticResponseType.FILERESPONSE } as StaticResponse
);
}
const lastMod = P.isJust(mdate) && P.isJust(mLastSent) && mdate.value.equals(mLastSent.value)
? T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse)
: P.isJust(mdate) ? respond({ 'Last-Modified': H.formatHttpDate(mdate.value) })
: respond({});
if (ss.useHash) {
return file.getHash
.chain(mHash => {
const lastHash = req.headers['if-none-match'];
if (lastHash != null && P.isJust(mHash)) {
const curHash = mHash.value;
if (ss.weakEtags && (lastHash === curHash || lastHash === `W/${curHash}`
|| `W/${lastHash}` === curHash)) {
return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
}
if (!ss.weakEtags && (curHash === lastHash && lastHash.indexOf('W/') !== 0)) {
return T.pure({ tag: StaticResponseType.NOTMODIFIED } as StaticResponse);
}
}
if (P.isJust(mHash)) {
return respond({ 'ETag': mHash.value });
}
return lastMod;
});
}
return lastMod;
}
示例3: formatHttpDate
const fileDate = T.node(null, path.join(__dirname, 'fixture', 'attic', 'a'), fs.stat).map(stat => {
return formatHttpDate(fromDate(stat.mtime));
});
示例4: createFileInfo
function createFileInfo(name: string, size: number, dt: Date) {
const time = fromDate(dt);
const date = formatHttpDate(time);
return new FileInfo(name, size, time, date);
}