當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript wai.responseBuffer函數代碼示例

本文整理匯總了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);
      }
    });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:51,代碼來源:static.ts

示例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));
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:7,代碼來源:utils.ts

示例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'))));
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:20,代碼來源:static.ts

示例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')));
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:73,代碼來源:static.ts

示例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')));
 }
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:6,代碼來源:static.test.ts


注:本文中的@jonggrang/wai.responseBuffer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。