'stream' 事件
stream
<Http2Stream> 对流的引用headers
<HTTP/2 Headers Object> 描述标头的对象flags
<number> 相关的数字标志rawHeaders
<Array> 包含原始标头名称后跟它们各自值的数组。
当与服务器关联的 Http2Session
触发 'stream'
事件时,则将触发 'stream'
事件。
另见 Http2Session
的 'stream'
事件。
const http2 = require('http2');
const {
HTTP2_HEADER_METHOD,
HTTP2_HEADER_PATH,
HTTP2_HEADER_STATUS,
HTTP2_HEADER_CONTENT_TYPE
} = http2.constants;
const options = getOptionsSomehow();
const server = http2.createSecureServer(options);
server.on('stream', (stream, headers, flags) => {
const method = headers[HTTP2_HEADER_METHOD];
const path = headers[HTTP2_HEADER_PATH];
// ...
stream.respond({
[HTTP2_HEADER_STATUS]: 200,
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain; charset=utf-8'
});
stream.write('hello ');
stream.end('world');
});
stream
<Http2Stream> A reference to the streamheaders
<HTTP/2 Headers Object> An object describing the headersflags
<number> The associated numeric flagsrawHeaders
<Array> An array containing the raw header names followed by their respective values.
The 'stream'
event is emitted when a 'stream'
event has been emitted by
an Http2Session
associated with the server.
See also Http2Session
's 'stream'
event.
const http2 = require('http2');
const {
HTTP2_HEADER_METHOD,
HTTP2_HEADER_PATH,
HTTP2_HEADER_STATUS,
HTTP2_HEADER_CONTENT_TYPE
} = http2.constants;
const options = getOptionsSomehow();
const server = http2.createSecureServer(options);
server.on('stream', (stream, headers, flags) => {
const method = headers[HTTP2_HEADER_METHOD];
const path = headers[HTTP2_HEADER_PATH];
// ...
stream.respond({
[HTTP2_HEADER_STATUS]: 200,
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain; charset=utf-8'
});
stream.write('hello ');
stream.end('world');
});