當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。