当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ServerResponse.setHeader方法代码示例

本文整理汇总了TypeScript中http.ServerResponse.setHeader方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerResponse.setHeader方法的具体用法?TypeScript ServerResponse.setHeader怎么用?TypeScript ServerResponse.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.ServerResponse的用法示例。


在下文中一共展示了ServerResponse.setHeader方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setTimeout

    echoServer.use(function(req: IncomingMessage, res: ServerResponse) {
        let urlParts = req.url.split("?");

        let returnResponse = () => {
            res.setHeader('Content-Type', 'text/plain');
            res.writeHead(200);
            req.pipe(res);
        };

        if (urlParts.length > 1) {
            const parameters = querystring.parse(urlParts[1]);

            if (parameters.d) {
                res.setHeader('d', parameters.d);
            }
        
            if (parameters.t) {
                res.setHeader('t', parameters.t);
                setTimeout(returnResponse, parameters.t)
            }
            else {
                returnResponse();
            }
            return;
        }

        returnResponse();

    });
开发者ID:roberthardy,项目名称:rp,代码行数:29,代码来源:echoServer.ts

示例2: nocache

  return function nocache (_req: IncomingMessage, res: ServerResponse, next: () => void) {
    res.setHeader('Surrogate-Control', 'no-store');
    res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
    res.setHeader('Pragma', 'no-cache');
    res.setHeader('Expires', '0');

    next();
  };
开发者ID:helmetjs,项目名称:nocache,代码行数:8,代码来源:index.ts

示例3: dispatch

    static dispatch(request : IncomingMessage, response : ServerResponse)
    {
        response.statusCode = 200;
        response.setHeader('Content-Type', 'application/json');

        var headers = request.headers;
        var method : RequestMethod = toRequestMethod(request.method);
        var url : RequestUrl = new RequestUrl(request.url);
        var body = [];

        request.on('error', function (err) {
            console.error(err);
        }).on('data', function(bodyChunk : string) {
            body.push(bodyChunk);
        }).on('end', function (){

            response.on('error', function(err) {
                console.error(err);
            });

            var dispatcher : IDispatcher = DispatchGenerator.generate(headers, method, url);
            var responseBody : Object = dispatcher.dispatch(method);

            response.write(JSON.stringify(responseBody));
            response.end();

        });
    }
开发者ID:Anmfishe,项目名称:TeamUp,代码行数:28,代码来源:ServiceDispatcher.ts

示例4: function

 return function (req: ServerRequest, resp: ServerResponse) {
     resp.setHeader('Content-Type', 'application/json')
     if (req.method === 'GET') {
         bot.validate(req, resp)
     } else if (req.method === 'POST') {
         bot.parseMessagingEvent(req, resp)
     } else {
         resp.statusCode = 400
         resp.end()
     }
 }
开发者ID:nikinapi,项目名称:Messenger-Bot,代码行数:11,代码来源:bot.ts

示例5:

 const callback = (error, result) => {
   if (error) throw error;
   res.statusCode = result.statusCode;
   for (let key in result.headers) {
     if (result.headers.hasOwnProperty(key)) {
       res.setHeader(key, result.headers[key]);
     }
   }
   res.write(result.body);
   res.end();
 };
开发者ID:apollostack,项目名称:apollo-server,代码行数:11,代码来源:lambdaApollo.test.ts

示例6: checkForKillCommand

export function checkForKillCommand(req: IncomingMessage, res: ServerResponse, next: NextFunction) {
    if (req.url == "/kill") {
        res.setHeader('Content-Type', 'text/plain');
        res.writeHead(200);
        res.end("Goodbye");
        console.log("Received kill command");
        process.exit();
    }
    else
        next();
};
开发者ID:roberthardy,项目名称:rp,代码行数:11,代码来源:utils.ts

示例7: createServer

const server = createServer((req: IncomingMessage, res: ServerResponse) => {

  const credentials = auth(req);

  if (!credentials || credentials.name !== 'john' || credentials.pass !== 'secret') {
    res.statusCode = 401;
    res.setHeader('WWW-Authenticate', 'Basic realm="example"');
    res.end('Access denied');
  } else {
    res.end('Access granted');
  }
});
开发者ID:types,项目名称:npm-basic-auth,代码行数:12,代码来源:http.ts

示例8: set

  set(name: string, value: string, opts: Cookie = {}): this {
    if (!this.res) {
      throw new Error('You must specify at least: new Cookies(..., ServerResponse)')
    }
    const queuedHeader = asString(this.res.getHeader('Set-Cookie'))
    const header = queuedHeader ? [queuedHeader] : []

    header.push(serialize(name, value, opts))
    this.res.setHeader('Set-Cookie', header)

    return this // chainable
  }
开发者ID:chbrown,项目名称:cookies,代码行数:12,代码来源:index.ts

示例9: serverRequest

export function serverRequest(
	settings: Partial<ReactConverterSettings>,
	req: IncomingMessage,
	res: ServerResponse
) {
	const baseFolder = path.resolve(process.cwd(), process.env.DOCS || 'docs')

	let url = req.url

	if (!url) {
		return
	}

	url = decodeURIComponent(url)

	if (url.startsWith('/favicon.ico')) {
		url = favicon
	}

	if (url.startsWith(ASSETS)) {
		const filePath = path.join(__dirname, url.slice(ASSETS.length))
		res.setHeader('Content-Type', mime.contentType(path.extname(filePath)))
		return fs.readFileSync(filePath)
	}

	const urlPath = path.join(baseFolder, url)

	if (fs.existsSync(urlPath) && fs.statSync(urlPath).isFile()) {
		return fs.readFileSync(urlPath)
	} else {
		let indexPath = path.join(baseFolder, url, 'index.json')
		if (fs.existsSync(indexPath)) {
			const content = fs.readFileSync(indexPath).toString()
			res.setHeader('Content-Type', 'text/html; charset=utf-8')
			return renderHTML(JSON.parse(content).reflection, settings)
		} else {
			throw new Error(`File not found: ${url}`)
		}
	}
}
开发者ID:docscript,项目名称:docscript,代码行数:40,代码来源:server.ts

示例10:

        cookies.forEach(data => {
            let cookie = `${data.key}=${data.value}; `;

            if (data.maxAge !== undefined)
                cookie += `Max-Age = ${data.maxAge}; `;
            if (data.domain !== undefined)
                cookie += `Domain  = ${data.domain}; `;
            if (data.expires !== undefined)
                cookie += `Expires = ${data.expires}; `;
            if (data.path !== undefined) cookie += `Path    = ${data.path}; `;

            this.res.setHeader('Set-Cookie', cookie);
        });
开发者ID:lleobox,项目名称:flask-node,代码行数:13,代码来源:response.ts


注:本文中的http.ServerResponse.setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。