当前位置: 首页>>代码示例>>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;未经允许,请勿转载。