UNPKG

learnyounode

Version:

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.

600 lines (584 loc) 259 kB
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>HTTP/2 | Node.js v12.10.0 Documentation</title> <link rel="stylesheet" href="data:text/css;base64,LyogbGF0aW4tZXh0ICovCkBmb250LWZhY2UgewogIGZvbnQtZmFtaWx5OiAnTGF0byc7CiAgZm9udC1zdHlsZTogaXRhbGljOwogIGZvbnQtd2VpZ2h0OiA0MDA7CiAgc3JjOiBsb2NhbCgnTGF0byBJdGFsaWMnKSwgbG9jYWwoJ0xhdG8tSXRhbGljJyksIHVybChodHRwczovL2ZvbnRzLmdzdGF0aWMuY29tL3MvbGF0by92MTYvUzZ1OHc0Qk1VVFBIanhzQVVpLXFOaVhnN2VVMC53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDEwMC0wMjRGLCBVKzAyNTksIFUrMUUwMC0xRUZGLCBVKzIwMjAsIFUrMjBBMC0yMEFCLCBVKzIwQUQtMjBDRiwgVSsyMTEzLCBVKzJDNjAtMkM3RiwgVStBNzIwLUE3RkY7Cn0KLyogbGF0aW4gKi8KQGZvbnQtZmFjZSB7CiAgZm9udC1mYW1pbHk6ICdMYXRvJzsKICBmb250LXN0eWxlOiBpdGFsaWM7CiAgZm9udC13ZWlnaHQ6IDQwMDsKICBzcmM6IGxvY2FsKCdMYXRvIEl0YWxpYycpLCBsb2NhbCgnTGF0by1JdGFsaWMnKSwgdXJsKGh0dHBzOi8vZm9udHMuZ3N0YXRpYy5jb20vcy9sYXRvL3YxNi9TNnU4dzRCTVVUUEhqeHNBWEMtcU5pWGc3US53b2ZmMikgZm9ybWF0KCd3b2ZmMicpOwogIHVuaWNvZGUtcmFuZ2U6IFUrMDAwMC0wMEZGLCBVKzAxMzEsIFUrMDE1Mi0wMTUzLCBVKzAyQkItMDJCQywgVSswMkM2LCBV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F9jb21tZW50IHsKICBjb2xvcjogIzY2NjsKICBmb250LXdlaWdodDogbGlnaHRlcjsKfQo="> <link rel="canonical" href="https://nodejs.org/api/http2.html"> </head> <body class="alt apidoc" id="api-section-http2"> <div id="content" class="clearfix"> <div id="column2" class="interior"> <div id="intro" class="interior"> <a href="https://nodejs.org/" title="Go back to the home page"> Node.js </a> </div> <ul> <li><a href="https://nodejs.org/api/documentation.html" class="nav-documentation">About these Docs</a></li> <li><a href="https://nodejs.org/api/synopsis.html" class="nav-synopsis">Usage &amp; Example</a></li> </ul> <div class="line"></div> <ul> <li><a href="https://nodejs.org/api/assert.html" class="nav-assert">Assertion Testing</a></li> <li><a href="https://nodejs.org/api/async_hooks.html" class="nav-async_hooks">Async Hooks</a></li> <li><a href="https://nodejs.org/api/buffer.html" class="nav-buffer">Buffer</a></li> <li><a href="https://nodejs.org/api/addons.html" class="nav-addons">C++ Addons</a></li> <li><a href="https://nodejs.org/api/n-api.html" class="nav-n-api">C/C++ Addons - N-API</a></li> <li><a href="https://nodejs.org/api/child_process.html" class="nav-child_process">Child Processes</a></li> <li><a href="https://nodejs.org/api/cluster.html" class="nav-cluster">Cluster</a></li> <li><a href="https://nodejs.org/api/cli.html" class="nav-cli">Command Line Options</a></li> <li><a href="https://nodejs.org/api/console.html" class="nav-console">Console</a></li> <li><a href="https://nodejs.org/api/crypto.html" class="nav-crypto">Crypto</a></li> <li><a href="https://nodejs.org/api/debugger.html" class="nav-debugger">Debugger</a></li> <li><a href="https://nodejs.org/api/deprecations.html" class="nav-deprecations">Deprecated APIs</a></li> <li><a href="https://nodejs.org/api/dns.html" class="nav-dns">DNS</a></li> <li><a href="https://nodejs.org/api/domain.html" class="nav-domain">Domain</a></li> <li><a href="https://nodejs.org/api/esm.html" class="nav-esm">ECMAScript Modules</a></li> <li><a href="https://nodejs.org/api/errors.html" class="nav-errors">Errors</a></li> <li><a href="https://nodejs.org/api/events.html" class="nav-events">Events</a></li> <li><a href="https://nodejs.org/api/fs.html" class="nav-fs">File System</a></li> <li><a href="https://nodejs.org/api/globals.html" class="nav-globals">Globals</a></li> <li><a href="https://nodejs.org/api/http.html" class="nav-http">HTTP</a></li> <li><a href="https://nodejs.org/api/http2.html" class="nav-http2 active">HTTP/2</a></li> <li><a href="https://nodejs.org/api/https.html" class="nav-https">HTTPS</a></li> <li><a href="https://nodejs.org/api/inspector.html" class="nav-inspector">Inspector</a></li> <li><a href="https://nodejs.org/api/intl.html" class="nav-intl">Internationalization</a></li> <li><a href="https://nodejs.org/api/modules.html" class="nav-modules">Modules</a></li> <li><a href="https://nodejs.org/api/net.html" class="nav-net">Net</a></li> <li><a href="https://nodejs.org/api/os.html" class="nav-os">OS</a></li> <li><a href="https://nodejs.org/api/path.html" class="nav-path">Path</a></li> <li><a href="https://nodejs.org/api/perf_hooks.html" class="nav-perf_hooks">Performance Hooks</a></li> <li><a href="https://nodejs.org/api/policy.html" class="nav-policy">Policies</a></li> <li><a href="https://nodejs.org/api/process.html" class="nav-process">Process</a></li> <li><a href="https://nodejs.org/api/punycode.html" class="nav-punycode">Punycode</a></li> <li><a href="https://nodejs.org/api/querystring.html" class="nav-querystring">Query Strings</a></li> <li><a href="https://nodejs.org/api/readline.html" class="nav-readline">Readline</a></li> <li><a href="https://nodejs.org/api/repl.html" class="nav-repl">REPL</a></li> <li><a href="https://nodejs.org/api/report.html" class="nav-report">Report</a></li> <li><a href="https://nodejs.org/api/stream.html" class="nav-stream">Stream</a></li> <li><a href="https://nodejs.org/api/string_decoder.html" class="nav-string_decoder">String Decoder</a></li> <li><a href="https://nodejs.org/api/timers.html" class="nav-timers">Timers</a></li> <li><a href="https://nodejs.org/api/tls.html" class="nav-tls">TLS/SSL</a></li> <li><a href="https://nodejs.org/api/tracing.html" class="nav-tracing">Trace Events</a></li> <li><a href="https://nodejs.org/api/tty.html" class="nav-tty">TTY</a></li> <li><a href="https://nodejs.org/api/dgram.html" class="nav-dgram">UDP/Datagram</a></li> <li><a href="https://nodejs.org/api/url.html" class="nav-url">URL</a></li> <li><a href="https://nodejs.org/api/util.html" class="nav-util">Utilities</a></li> <li><a href="https://nodejs.org/api/v8.html" class="nav-v8">V8</a></li> <li><a href="https://nodejs.org/api/vm.html" class="nav-vm">VM</a></li> <li><a href="https://nodejs.org/api/worker_threads.html" class="nav-worker_threads">Worker Threads</a></li> <li><a href="https://nodejs.org/api/zlib.html" class="nav-zlib">Zlib</a></li> </ul> <div class="line"></div> <ul> <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">GitHub Repo &amp; Issue Tracker</a></li> </ul> </div> <div id="column1" data-id="http2" class="interior"> <header> <h1>Node.js v12.10.0 Documentation</h1> <div id="gtoc"> <ul> <li> <a href="https://nodejs.org/api/index.html" name="toc">Index</a> </li> <li> <a href="https://nodejs.org/api/all.html">View on single page</a> </li> <li> <a href="https://nodejs.org/api/http2.json">View as JSON</a> </li> <li class="version-picker"> <a href="#">View another version <span>▼</span></a> <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v12.x/api/http2.html">12.x</a></li> <li><a href="https://nodejs.org/docs/latest-v11.x/api/http2.html">11.x</a></li> <li><a href="https://nodejs.org/docs/latest-v10.x/api/http2.html">10.x <b>LTS</b></a></li> <li><a href="https://nodejs.org/docs/latest-v9.x/api/http2.html">9.x</a></li> <li><a href="https://nodejs.org/docs/latest-v8.x/api/http2.html">8.x <b>LTS</b></a></li></ol> </li> <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/http2.md"><span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"></path></svg></span>Edit on GitHub</a></li> </ul> </div> <hr> </header> <div id="toc"> <h2>Table of Contents</h2> <ul> <li> <p><span class="stability_2"><a href="#http2_http_2">HTTP/2</a></span></p> <ul> <li> <p><a href="#http2_core_api">Core API</a></p> <ul> <li><a href="#http2_server_side_example">Server-side example</a></li> <li><a href="#http2_client_side_example">Client-side example</a></li> <li> <p><a href="#http2_class_http2session">Class: Http2Session</a></p> <ul> <li><a href="#http2_http2session_and_sockets">Http2Session and Sockets</a></li> <li><a href="#http2_event_close">Event: 'close'</a></li> <li><a href="#http2_event_connect">Event: 'connect'</a></li> <li><a href="#http2_event_error">Event: 'error'</a></li> <li><a href="#http2_event_frameerror">Event: 'frameError'</a></li> <li><a href="#http2_event_goaway">Event: 'goaway'</a></li> <li><a href="#http2_event_localsettings">Event: 'localSettings'</a></li> <li><a href="#http2_event_ping">Event: 'ping'</a></li> <li><a href="#http2_event_remotesettings">Event: 'remoteSettings'</a></li> <li><a href="#http2_event_stream">Event: 'stream'</a></li> <li><a href="#http2_event_timeout">Event: 'timeout'</a></li> <li><a href="#http2_http2session_alpnprotocol">http2session.alpnProtocol</a></li> <li><a href="#http2_http2session_close_callback">http2session.close([callback])</a></li> <li><a href="#http2_http2session_closed">http2session.closed</a></li> <li><a href="#http2_http2session_connecting">http2session.connecting</a></li> <li><a href="#http2_http2session_destroy_error_code">http2session.destroy([error][, code])</a></li> <li><a href="#http2_http2session_destroyed">http2session.destroyed</a></li> <li><a href="#http2_http2session_encrypted">http2session.encrypted</a></li> <li><a href="#http2_http2session_goaway_code_laststreamid_opaquedata">http2session.goaway([code[, lastStreamID[, opaqueData]]])</a></li> <li><a href="#http2_http2session_localsettings">http2session.localSettings</a></li> <li><a href="#http2_http2session_originset">http2session.originSet</a></li> <li><a href="#http2_http2session_pendingsettingsack">http2session.pendingSettingsAck</a></li> <li><a href="#http2_http2session_ping_payload_callback">http2session.ping([payload, ]callback)</a></li> <li><a href="#http2_http2session_ref">http2session.ref()</a></li> <li><a href="#http2_http2session_remotesettings">http2session.remoteSettings</a></li> <li><a href="#http2_http2session_settimeout_msecs_callback">http2session.setTimeout(msecs, callback)</a></li> <li><a href="#http2_http2session_socket">http2session.socket</a></li> <li><a href="#http2_http2session_state">http2session.state</a></li> <li><a href="#http2_http2session_settings_settings_callback">http2session.settings([settings][, callback])</a></li> <li><a href="#http2_http2session_type">http2session.type</a></li> <li><a href="#http2_http2session_unref">http2session.unref()</a></li> </ul> </li> <li> <p><a href="#http2_class_serverhttp2session">Class: ServerHttp2Session</a></p> <ul> <li><a href="#http2_serverhttp2session_altsvc_alt_originorstream">serverhttp2session.altsvc(alt, originOrStream)</a></li> <li><a href="#http2_specifying_alternative_services">Specifying alternative services</a></li> <li><a href="#http2_serverhttp2session_origin_origins">serverhttp2session.origin(...origins)</a></li> </ul> </li> <li> <p><a href="#http2_class_clienthttp2session">Class: ClientHttp2Session</a></p> <ul> <li><a href="#http2_event_altsvc">Event: 'altsvc'</a></li> <li><a href="#http2_event_origin">Event: 'origin'</a></li> <li><a href="#http2_clienthttp2session_request_headers_options">clienthttp2session.request(headers[, options])</a></li> </ul> </li> <li> <p><a href="#http2_class_http2stream">Class: Http2Stream</a></p> <ul> <li> <p><a href="#http2_http2stream_lifecycle">Http2Stream Lifecycle</a></p> <ul> <li><a href="#http2_creation">Creation</a></li> <li><a href="#http2_destruction">Destruction</a></li> </ul> </li> <li><a href="#http2_event_aborted">Event: 'aborted'</a></li> <li><a href="#http2_event_close_1">Event: 'close'</a></li> <li><a href="#http2_event_error_1">Event: 'error'</a></li> <li><a href="#http2_event_frameerror_1">Event: 'frameError'</a></li> <li><a href="#http2_event_timeout_1">Event: 'timeout'</a></li> <li><a href="#http2_event_trailers">Event: 'trailers'</a></li> <li><a href="#http2_event_wanttrailers">Event: 'wantTrailers'</a></li> <li><a href="#http2_http2stream_aborted">http2stream.aborted</a></li> <li><a href="#http2_http2stream_buffersize">http2stream.bufferSize</a></li> <li><a href="#http2_http2stream_close_code_callback">http2stream.close(code[, callback])</a></li> <li><a href="#http2_http2stream_closed">http2stream.closed</a></li> <li><a href="#http2_http2stream_destroyed">http2stream.destroyed</a></li> <li><a href="#http2_http2stream_endafterheaders">http2stream.endAfterHeaders</a></li> <li><a href="#http2_http2stream_id">http2stream.id</a></li> <li><a href="#http2_http2stream_pending">http2stream.pending</a></li> <li><a href="#http2_http2stream_priority_options">http2stream.priority(options)</a></li> <li><a href="#http2_http2stream_rstcode">http2stream.rstCode</a></li> <li><a href="#http2_http2stream_sentheaders">http2stream.sentHeaders</a></li> <li><a href="#http2_http2stream_sentinfoheaders">http2stream.sentInfoHeaders</a></li> <li><a href="#http2_http2stream_senttrailers">http2stream.sentTrailers</a></li> <li><a href="#http2_http2stream_session">http2stream.session</a></li> <li><a href="#http2_http2stream_settimeout_msecs_callback">http2stream.setTimeout(msecs, callback)</a></li> <li><a href="#http2_http2stream_state">http2stream.state</a></li> <li><a href="#http2_http2stream_sendtrailers_headers">http2stream.sendTrailers(headers)</a></li> </ul> </li> <li> <p><a href="#http2_class_clienthttp2stream">Class: ClientHttp2Stream</a></p> <ul> <li><a href="#http2_event_continue">Event: 'continue'</a></li> <li><a href="#http2_event_headers">Event: 'headers'</a></li> <li><a href="#http2_event_push">Event: 'push'</a></li> <li><a href="#http2_event_response">Event: 'response'</a></li> </ul> </li> <li> <p><a href="#http2_class_serverhttp2stream">Class: ServerHttp2Stream</a></p> <ul> <li><a href="#http2_http2stream_additionalheaders_headers">http2stream.additionalHeaders(headers)</a></li> <li><a href="#http2_http2stream_headerssent">http2stream.headersSent</a></li> <li><a href="#http2_http2stream_pushallowed">http2stream.pushAllowed</a></li> <li><a href="#http2_http2stream_pushstream_headers_options_callback">http2stream.pushStream(headers[, options], callback)</a></li> <li><a href="#http2_http2stream_respond_headers_options">http2stream.respond([headers[, options]])</a></li> <li><a href="#http2_http2stream_respondwithfd_fd_headers_options">http2stream.respondWithFD(fd[, headers[, options]])</a></li> <li><a href="#http2_http2stream_respondwithfile_path_headers_options">http2stream.respondWithFile(path[, headers[, options]])</a></li> </ul> </li> <li> <p><a href="#http2_class_http2server">Class: Http2Server</a></p> <ul> <li><a href="#http2_event_checkcontinue">Event: 'checkContinue'</a></li> <li><a href="#http2_event_request">Event: 'request'</a></li> <li><a href="#http2_event_session">Event: 'session'</a></li> <li><a href="#http2_event_sessionerror">Event: 'sessionError'</a></li> <li><a href="#http2_event_stream_1">Event: 'stream'</a></li> <li><a href="#http2_event_timeout_2">Event: 'timeout'</a></li> <li><a href="#http2_server_close_callback">server.close([callback])</a></li> <li><a href="#http2_server_settimeout_msecs_callback">server.setTimeout([msecs][, callback])</a></li> </ul> </li> <li> <p><a href="#http2_class_http2secureserver">Class: Http2SecureServer</a></p> <ul> <li><a href="#http2_event_checkcontinue_1">Event: 'checkContinue'</a></li> <li><a href="#http2_event_request_1">Event: 'request'</a></li> <li><a href="#http2_event_session_1">Event: 'session'</a></li> <li><a href="#http2_event_sessionerror_1">Event: 'sessionError'</a></li> <li><a href="#http2_event_stream_2">Event: 'stream'</a></li> <li><a href="#http2_event_timeout_3">Event: 'timeout'</a></li> <li><a href="#http2_event_unknownprotocol">Event: 'unknownProtocol'</a></li> <li><a href="#http2_server_close_callback_1">server.close([callback])</a></li> <li><a href="#http2_server_settimeout_msecs_callback_1">server.setTimeout([msecs][, callback])</a></li> </ul> </li> <li><a href="#http2_http2_createserver_options_onrequesthandler">http2.createServer(options[, onRequestHandler])</a></li> <li><a href="#http2_http2_createsecureserver_options_onrequesthandler">http2.createSecureServer(options[, onRequestHandler])</a></li> <li><a href="#http2_http2_connect_authority_options_listener">http2.connect(authority[, options][, listener])</a></li> <li> <p><a href="#http2_http2_constants">http2.constants</a></p> <ul> <li><a href="#http2_error_codes_for_rst_stream_and_goaway">Error Codes for RST_STREAM and GOAWAY</a></li> </ul> </li> <li><a href="#http2_http2_getdefaultsettings">http2.getDefaultSettings()</a></li> <li><a href="#http2_http2_getpackedsettings_settings">http2.getPackedSettings([settings])</a></li> <li><a href="#http2_http2_getunpackedsettings_buf">http2.getUnpackedSettings(buf)</a></li> <li><a href="#http2_headers_object">Headers Object</a></li> <li><a href="#http2_settings_object">Settings Object</a></li> <li><a href="#http2_using_options_selectpadding">Using <code>options.selectPadding()</code></a></li> <li><a href="#http2_error_handling">Error Handling</a></li> <li><a href="#http2_invalid_character_handling_in_header_names_and_values">Invalid character handling in header names and values</a></li> <li><a href="#http2_push_streams_on_the_client">Push streams on the client</a></li> <li><a href="#http2_supporting_the_connect_method">Supporting the CONNECT method</a></li> <li><a href="#http2_the_extended_connect_protocol">The Extended CONNECT Protocol</a></li> </ul> </li> <li> <p><a href="#http2_compatibility_api">Compatibility API</a></p> <ul> <li><a href="#http2_alpn_negotiation">ALPN negotiation</a></li> <li> <p><a href="#http2_class_http2_http2serverrequest">Class: http2.Http2ServerRequest</a></p> <ul> <li><a href="#http2_event_aborted_1">Event: 'aborted'</a></li> <li><a href="#http2_event_close_2">Event: 'close'</a></li> <li><a href="#http2_request_aborted">request.aborted</a></li> <li><a href="#http2_request_authority">request.authority</a></li> <li><a href="#http2_request_destroy_error">request.destroy([error])</a></li> <li><a href="#http2_request_headers">request.headers</a></li> <li><a href="#http2_request_httpversion">request.httpVersion</a></li> <li><a href="#http2_request_method">request.method</a></li> <li><a href="#http2_request_rawheaders">request.rawHeaders</a></li> <li><a href="#http2_request_rawtrailers">request.rawTrailers</a></li> <li><a href="#http2_request_scheme">request.scheme</a></li> <li><a href="#http2_request_settimeout_msecs_callback">request.setTimeout(msecs, callback)</a></li> <li><a href="#http2_request_socket">request.socket</a></li> <li><a href="#http2_request_stream">request.stream</a></li> <li><a href="#http2_request_trailers">request.trailers</a></li> <li><a href="#http2_request_url">request.url</a></li> </ul> </li> <li> <p><a href="#http2_class_http2_http2serverresponse">Class: http2.Http2ServerResponse</a></p> <ul> <li><a href="#http2_event_close_3">Event: 'close'</a></li> <li><a href="#http2_event_finish">Event: 'finish'</a></li> <li><a href="#http2_response_addtrailers_headers">response.addTrailers(headers)</a></li> <li><a href="#http2_response_connection">response.connection</a></li> <li><a href="#http2_response_end_data_encoding_callback">response.end([data][, encoding][, callback])</a></li> <li><a href="#http2_response_finished">response.finished</a></li> <li><a href="#http2_response_getheader_name">response.getHeader(name)</a></li> <li><a href="#http2_response_getheadernames">response.getHeaderNames()</a></li> <li><a href="#http2_response_getheaders">response.getHeaders()</a></li> <li><a href="#http2_response_hasheader_name">response.hasHeader(name)</a></li> <li><a href="#http2_response_headerssent">response.headersSent</a></li> <li><a href="#http2_response_removeheader_name">response.removeHeader(name)</a></li> <li><a href="#http2_response_senddate">response.sendDate</a></li> <li><a href="#http2_response_setheader_name_value">response.setHeader(name, value)</a></li> <li><a href="#http2_response_settimeout_msecs_callback">response.setTimeout(msecs[, callback])</a></li> <li><a href="#http2_response_socket">response.socket</a></li> <li><a href="#http2_response_statuscode">response.statusCode</a></li> <li><a href="#http2_response_statusmessage">response.statusMessage</a></li> <li><a href="#http2_response_stream">response.stream</a></li> <li><a href="#http2_response_writableended">response.writableEnded</a></li> <li><a href="#http2_response_write_chunk_encoding_callback">response.write(chunk[, encoding][, callback])</a></li> <li><a href="#http2_response_writecontinue">response.writeContinue()</a></li> <li><a href="#http2_response_writehead_statuscode_statusmessage_headers">response.writeHead(statusCode[, statusMessage][, headers])</a></li> <li><a href="#http2_response_createpushresponse_headers_callback">response.createPushResponse(headers, callback)</a></li> </ul> </li> </ul> </li> <li><a href="#http2_collecting_http_2_performance_metrics">Collecting HTTP/2 Performance Metrics</a></li> </ul> </li> </ul> </div> <div id="apicontent"> <h1>HTTP/2<span><a class="mark" href="#http2_http_2" id="http2_http_2">#</a></span></h1> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v10.10.0</td> <td><p>HTTP/2 is now Stable. Previously, it had been Experimental.</p></td></tr> <tr><td>v8.4.0</td> <td><p><span>Added in: v8.4.0</span></p></td></tr> </tbody></table> </details> </div> <p></p><div class="api_stability api_stability_2"><a href="https://nodejs.org/api/documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p> <p>The <code>http2</code> module provides an implementation of the <a href="https://tools.ietf.org/html/rfc7540">HTTP/2</a> protocol. It can be accessed using:</p> <pre><code class="language-js">const http2 = require('http2'); </code></pre> <h2>Core API<span><a class="mark" href="#http2_core_api" id="http2_core_api">#</a></span></h2> <p>The Core API provides a low-level interface designed specifically around support for HTTP/2 protocol features. It is specifically <em>not</em> designed for compatibility with the existing <a href="https://nodejs.org/api/http.html">HTTP/1</a> module API. However, the <a href="#http2_compatibility_api">Compatibility API</a> is.</p> <p>The <code>http2</code> Core API is much more symmetric between client and server than the <code>http</code> API. For instance, most events, like <code>'error'</code>, <code>'connect'</code> and <code>'stream'</code>, can be emitted either by client-side code or server-side code.</p> <h3>Server-side example<span><a class="mark" href="#http2_server_side_example" id="http2_server_side_example">#</a></span></h3> <p>The following illustrates a simple HTTP/2 server using the Core API. Since there are no browsers known that support <a href="https://http2.github.io/faq/#does-http2-require-encryption">unencrypted HTTP/2</a>, the use of <a href="#http2_http2_createsecureserver_options_onrequesthandler"><code>http2.createSecureServer()</code></a> is necessary when communicating with browser clients.</p> <pre><code class="language-js">const http2 = require('http2'); const fs = require('fs'); const server = http2.createSecureServer({ key: fs.readFileSync('localhost-privkey.pem'), cert: fs.readFileSync('localhost-cert.pem') }); server.on('error', (err) =&gt; console.error(err)); server.on('stream', (stream, headers) =&gt; { // stream is a Duplex stream.respond({ 'content-type': 'text/html', ':status': 200 }); stream.end('&lt;h1&gt;Hello World&lt;/h1&gt;'); }); server.listen(8443); </code></pre> <p>To generate the certificate and key for this example, run:</p> <pre><code class="language-bash">openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \ -keyout localhost-privkey.pem -out localhost-cert.pem </code></pre> <h3>Client-side example<span><a class="mark" href="#http2_client_side_example" id="http2_client_side_example">#</a></span></h3> <p>The following illustrates an HTTP/2 client:</p> <pre><code class="language-js">const http2 = require('http2'); const fs = require('fs'); const client = http2.connect('https://localhost:8443', { ca: fs.readFileSync('localhost-cert.pem') }); client.on('error', (err) =&gt; console.error(err)); const req = client.request({ ':path': '/' }); req.on('response', (headers, flags) =&gt; { for (const name in headers) { console.log(`${name}: ${headers[name]}`); } }); req.setEncoding('utf8'); let data = ''; req.on('data', (chunk) =&gt; { data += chunk; }); req.on('end', () =&gt; { console.log(`\n${data}`); client.close(); }); req.end(); </code></pre> <h3>Class: Http2Session<span><a class="mark" href="#http2_class_http2session" id="http2_class_http2session">#</a></span></h3> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li>Extends: <a href="https://nodejs.org/api/events.html#events_class_eventemitter" class="type">&lt;EventEmitter&gt;</a></li> </ul> <p>Instances of the <code>http2.Http2Session</code> class represent an active communications session between an HTTP/2 client and server. Instances of this class are <em>not</em> intended to be constructed directly by user code.</p> <p>Each <code>Http2Session</code> instance will exhibit slightly different behaviors depending on whether it is operating as a server or a client. The <code>http2session.type</code> property can be used to determine the mode in which an <code>Http2Session</code> is operating. On the server side, user code should rarely have occasion to work with the <code>Http2Session</code> object directly, with most actions typically taken through interactions with either the <code>Http2Server</code> or <code>Http2Stream</code> objects.</p> <p>User code will not create <code>Http2Session</code> instances directly. Server-side <code>Http2Session</code> instances are created by the <code>Http2Server</code> instance when a new HTTP/2 connection is received. Client-side <code>Http2Session</code> instances are created using the <code>http2.connect()</code> method.</p> <h4>Http2Session and Sockets<span><a class="mark" href="#http2_http2session_and_sockets" id="http2_http2session_and_sockets">#</a></span></h4> <p>Every <code>Http2Session</code> instance is associated with exactly one <a href="https://nodejs.org/api/net.html#net_class_net_socket"><code>net.Socket</code></a> or <a href="https://nodejs.org/api/tls.html#tls_class_tls_tlssocket"><code>tls.TLSSocket</code></a> when it is created. When either the <code>Socket</code> or the <code>Http2Session</code> are destroyed, both will be destroyed.</p> <p>Because of the specific serialization and processing requirements imposed by the HTTP/2 protocol, it is not recommended for user code to read data from or write data to a <code>Socket</code> instance bound to a <code>Http2Session</code>. Doing so can put the HTTP/2 session into an indeterminate state causing the session and the socket to become unusable.</p> <p>Once a <code>Socket</code> has been bound to an <code>Http2Session</code>, user code should rely solely on the API of the <code>Http2Session</code>.</p> <h4>Event: 'close'<span><a class="mark" href="#http2_event_close" id="http2_event_close">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <p>The <code>'close'</code> event is emitted once the <code>Http2Session</code> has been destroyed. Its listener does not expect any arguments.</p> <h4>Event: 'connect'<span><a class="mark" href="#http2_event_connect" id="http2_event_connect">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>session</code> <a href="https://nodejs.org/api/http2.html#http2_class_http2session" class="type">&lt;Http2Session&gt;</a></li> <li><code>socket</code> <a href="https://nodejs.org/api/net.html#net_class_net_socket" class="type">&lt;net.Socket&gt;</a></li> </ul> <p>The <code>'connect'</code> event is emitted once the <code>Http2Session</code> has been successfully connected to the remote peer and communication may begin.</p> <p>User code will typically not listen for this event directly.</p> <h4>Event: 'error'<span><a class="mark" href="#http2_event_error" id="http2_event_error">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a></li> </ul> <p>The <code>'error'</code> event is emitted when an error occurs during the processing of an <code>Http2Session</code>.</p> <h4>Event: 'frameError'<span><a class="mark" href="#http2_event_frameerror" id="http2_event_frameerror">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> The frame type.</li> <li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> The error code.</li> <li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;integer&gt;</a> The stream id (or <code>0</code> if the frame isn't associated with a stream).</li> </ul> <p>The <code>'frameError'</code> event is emitted when an error occurs while attempting to send a frame on the session. If the frame that could not be sent is associated with a specific <code>Http2Stream</code>, an attempt to emit a <code>'frameError'</code> event on the <code>Http2Stream</code> is made.</p> <p>If the <code>'frameError'</code> event is associated with a stream, the stream will be closed and destroyed immediately following the <code>'frameError'</code> event. If the event is not associated with a stream, the <code>Http2Session</code> will be shut down immediately following the <code>'frameError'</code> event.</p> <h4>Event: 'goaway'<span><a class="mark" href="#http2_event_goaway" id="http2_event_goaway">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>errorCode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The HTTP/2 error code specified in the <code>GOAWAY</code> frame.</li> <li><code>lastStreamID</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The ID of the last stream the remote peer successfully processed (or <code>0</code> if no ID is specified).</li> <li><code>opaqueData</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> If additional opaque data was included in the <code>GOAWAY</code> frame, a <code>Buffer</code> instance will be passed containing that data.</li> </ul> <p>The <code>'goaway'</code> event is emitted when a <code>GOAWAY</code> frame is received.</p> <p>The <code>Http2Session</code> instance will be shut down automatically when the <code>'goaway'</code> event is emitted.</p> <h4>Event: 'localSettings'<span><a class="mark" href="#http2_event_localsettings" id="http2_event_localsettings">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>settings</code> <a href="https://nodejs.org/api/http2.html#http2_settings_object" class="type">&lt;HTTP/2 Settings Object&gt;</a> A copy of the <code>SETTINGS</code> frame received.</li> </ul> <p>The <code>'localSettings'</code> event is emitted when an acknowledgment <code>SETTINGS</code> frame has been received.</p> <p>When using <code>http2session.settings()</code> to submit new settings, the modified settings do not take effect until the <code>'localSettings'</code> event is emitted.</p> <pre><code class="language-js">session.settings({ enablePush: false }); session.on('localSettings', (settings) =&gt; { /* Use the new settings */ }); </code></pre> <h4>Event: 'ping'<span><a class="mark" href="#http2_event_ping" id="http2_event_ping">#</a></span></h4> <div class="api_metadata"> <span>Added in: v10.12.0</span> </div> <ul> <li><code>payload</code> <a href="https://nodejs.org/api/buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The <code>PING</code> frame 8-byte payload</li> </ul> <p>The <code>'ping'</code> event is emitted whenever a <code>PING</code> frame is received from the connected peer.</p> <h4>Event: 'remoteSettings'<span><a class="mark" href="#http2_event_remotesettings" id="http2_event_remotesettings">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>settings</code> <a href="https://nodejs.org/api/http2.html#http2_settings_object" class="type">&lt;HTTP/2 Settings Object&gt;</a> A copy of the <code>SETTINGS</code> frame received.</li> </ul> <p>The <code>'remoteSettings'</code> event is emitted when a new <code>SETTINGS</code> frame is received from the connected peer.</p> <pre><code class="language-js">session.on('remoteSettings', (settings) =&gt; { /* Use the new settings */ }); </code></pre> <h4>Event: 'stream'<span><a class="mark" href="#http2_event_stream" id="http2_event_stream">#</a></span></h4> <div class="api_metadata"> <span>Added in: v8.4.0</span> </div> <ul> <li><code>stream</code> <a href="https://nodejs.org/api/http2.html#http2_class_http2stream" class="type">&lt;Http2Stream&gt;</a> A reference to the stream</li> <li><code>headers</code> <a href="https://nodejs.org/api/http2.html#http2_headers_object" class="type">&lt;HTTP/2 Headers Object&gt;</a> An object describing the headers</li> <li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The associated numeric flags</li> <li><code>rawHeaders</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> An array containing the raw header names followed by their respective values.</li> </ul> <p>The <code>'stream'</code> event is emitted when a new <code>Http2Stream</code> is created.</p> <pre><code class="language-js">const http2 = require('http2'); session.on('stream', (stream, headers, flags) =&gt; { const method = headers[':method']; const path = headers[':path']; // ... stream.respond({ ':status': 200, 'content-type': 'text/plain' }); stream.write('hello '); stream.end('world'); }); </code></pre> <p>On the server side, user code will typically not listen for this event directly, and would instead register a handler for the <code>'stream'</code> event emitted by the <code>net.Server</code> or <code>tls.Server</code> instances returned by <code>http2.createServer()</code> and <code>http2.createSecureServer()</code>, respectively, as in the example below:</p> <pre><code class="language-js">const http2 = require('http2'); // Create an unencrypted HTTP/2 server const server = http2.createServer(); server.on('stream', (stream, headers) =&gt; { stream.respond({ 'content-type': 'text/html', ':status': 200 }); stream.on('error', (error) =&gt; console.error(error)); stream.end('&lt;h1&gt;Hello World&lt;/h1&gt;'); }); server.listen(80); </code></pre> <p>Even though HTTP/2 streams and network sockets are not in a 1:1 correspondence, a network error will destroy each individual stream and must be handled on the strea