本文整理汇总了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);
}