本文整理匯總了TypeScript中@jonggrang/wai.responseBuffer函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript responseBuffer函數的具體用法?TypeScript responseBuffer怎麽用?TypeScript responseBuffer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了responseBuffer函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: switch
.chain(srespond => {
switch (srespond.tag) {
case StaticResponseType.FILERESPONSE:
const { file } = srespond;
return ss.getMimeType(file)
.chain(mime => {
const headers = S.assign({}, srespond.headers, {
'Content-Type': mime
});
return sendResponse(file.toResponse(200, headers));
});
case StaticResponseType.NOTMODIFIED:
return sendResponse(W.responseBuffer(304, {}, Buffer.from('')));
case StaticResponseType.SENDCONTENT:
return sendResponse(W.responseReadable(200, {
'Content-Type': srespond.mimeType
}, srespond.readable));
case StaticResponseType.REDIRECT:
const reqQs = url.parse(req.url as string, true).query;
const loc = ss.mkRedirect(srespond.pieces, srespond.pieces.map(encodeURIComponent).join('/'));
const qString =
P.isJust(srespond.hash)
? S.assign({}, reqQs, { etag: srespond.hash.value })
: S.remove('etag', reqQs as any);
const qs = H.renderQuery(qString as any);
return sendResponse(W.responseBuffer(301, {
'Content-Type': 'text/plain',
Location: loc + (qs !== '' ? `?${qs}` : '')
}, Buffer.from('')));
case StaticResponseType.RAWREDIRECT:
return sendResponse(W.responseBuffer(301, {
'Content-Type': 'text/plain',
Location: srespond.path
}, Buffer.from('Redirect')));
case StaticResponseType.NOTFOUND:
if (P.isJust(ss.notFoundHandler)) {
return ss.notFoundHandler.value(ctx, sendResponse);
}
return sendResponse(W.responseBuffer(404, {
'Content-Type': 'text/plain'
}, Buffer.from('File not found')));
case StaticResponseType.WAIRESPONSE:
return sendResponse(srespond.response);
}
});
示例2: respond
export function simpleApp<A>(ctx: W.HttpContext, respond: (_: W.Response) => T.Task<A>): T.Task<A> {
const body = Buffer.from('simple app');
return respond(W.responseBuffer(200, {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(body)
}, body));
}
示例3: serveFolder
export function serveFolder(
settings: StaticSettings, pieces: Piece[],
req: IncomingMessage, folder: Folder
): T.Task<StaticResponse> {
if (P.isNothing(settings.listing)) {
return T.pure(waiStaticResponse(W.responseBuffer(403, {
'Content-Type': 'text/plain'
}, Buffer.from('Directory listings disabled'))));
}
if (settings.addTrailingSlash) {
const path = addTrailingSlash(req);
if (path != null) return T.pure({ tag: StaticResponseType.RAWREDIRECT, path: path } as StaticResponse);
}
const listing = settings.listing.value;
return T.pure(waiStaticResponse(W.responseBuffer(200, {
'Content-Type': 'text/html; charset=utf-8'
}, Buffer.from(listing(pieces, folder), 'utf8'))));
}
示例4: sendResponse
function staticAppPieces<A>(
ss: StaticSettings,
rawPieces: string[],
ctx: W.HttpContext,
sendResponse: (resp: W.Response) => T.Task<A>
): T.Task<A> {
const req = ctx.request;
if (['GET', 'HEAD'].indexOf(req.method as string) === -1) {
return sendResponse(W.responseBuffer(405, {
'Content-Type': 'text/plain'
}, Buffer.from('Only GET or HEAD is supported')));
}
const mpieces = toPieces(rawPieces);
if (P.isJust(mpieces)) {
return checkPieces(ss, mpieces.value, req)
.chain(srespond => {
switch (srespond.tag) {
case StaticResponseType.FILERESPONSE:
const { file } = srespond;
return ss.getMimeType(file)
.chain(mime => {
const headers = S.assign({}, srespond.headers, {
'Content-Type': mime
});
return sendResponse(file.toResponse(200, headers));
});
case StaticResponseType.NOTMODIFIED:
return sendResponse(W.responseBuffer(304, {}, Buffer.from('')));
case StaticResponseType.SENDCONTENT:
return sendResponse(W.responseReadable(200, {
'Content-Type': srespond.mimeType
}, srespond.readable));
case StaticResponseType.REDIRECT:
const reqQs = url.parse(req.url as string, true).query;
const loc = ss.mkRedirect(srespond.pieces, srespond.pieces.map(encodeURIComponent).join('/'));
const qString =
P.isJust(srespond.hash)
? S.assign({}, reqQs, { etag: srespond.hash.value })
: S.remove('etag', reqQs as any);
const qs = H.renderQuery(qString as any);
return sendResponse(W.responseBuffer(301, {
'Content-Type': 'text/plain',
Location: loc + (qs !== '' ? `?${qs}` : '')
}, Buffer.from('')));
case StaticResponseType.RAWREDIRECT:
return sendResponse(W.responseBuffer(301, {
'Content-Type': 'text/plain',
Location: srespond.path
}, Buffer.from('Redirect')));
case StaticResponseType.NOTFOUND:
if (P.isJust(ss.notFoundHandler)) {
return ss.notFoundHandler.value(ctx, sendResponse);
}
return sendResponse(W.responseBuffer(404, {
'Content-Type': 'text/plain'
}, Buffer.from('File not found')));
case StaticResponseType.WAIRESPONSE:
return sendResponse(srespond.response);
}
});
}
return sendResponse(W.responseBuffer(403, {
'Content-Type': 'text/plain'
}, Buffer.from('Forbidden')));
}
示例5: respond
function notFoundHandler<A>(ctx: HttpContext, respond: (_: Response) => T.Task<A>): T.Task<A> {
return respond(responseBuffer(404, {
'Content-Type': 'text/plain',
'X-Powered-By': 'wai-static'
}, Buffer.from('This is not a page you are looking for', 'utf8')));
}