成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

【搬運(yùn)工】Say hello to HTTP/2 for Node.js Core

HelKyle / 1914人閱讀

來源:Say hello to HTTP/2 for Node.js Core – Node.js Collection – Medium

A few minutes ago I opened the initial pull-request that would provide an implementation of HTTP/2 for Node.js core. While it’s far from being production ready, this marks a key milestone.

Because this is just a pull-request, it’s possible to play around with, but there are a few additional steps.

First, you’ll need to make sure you’re set up for building Node.js locally by following the instructions here: https://github.com/nodejs/nod...

After that, check out the working branch:

$ git clone https://github.com/jasnell/node
$ git checkout initial-pr

Then build...

$ ./configure
$ make -j8

Warning, building Node.js from scratch takes quite a bit of time. So go grab a quick snack while things get going.

Once complete, you can create a functioning HTTP/2 server in a few lines of code:

const http2 = require("http2");
const server = http2.createServer();
server.on("stream", (stream, requestHeaders) => {
  stream.respond({ ":status": 200, "content-type": "text/plain" });
  stream.write("hello ");
  stream.end("world");
});
server.listen(8000);

Because the HTTP/2 support is still experimental, in order to run this server, the Node.js instance must be started using the --expose-http2 command line argument:

$ node --expose-http2 h2server.js

Note that the server above uses plain-text TCP connection so the server will not be accessible from Web Browsers, which require using TLS. We can, however, create a simple HTTP/2 client:

const http2 = require("http2");
const client = http2.connect("http://localhost:8000");
const req = client.request({ ":method": "GET", ":path": "/" });
req.on("response", (responseHeaders) => {
  // do something with the headers
});
req.on("data", (chunk) => {
  // do something with the data
});
req.on("end", () => client.destroy());

Setting up a TLS-enabled HTTP/2 server requires just a few more additional steps:

const http2 = require("http2");
const options = {
  key: getKeySomehow(),
  cert: getCertSomehow()
};
const server = http2.createSecureServer(options);
server.on("stream", (stream, requestHeaders) => {
  stream.respond();
  stream.end("secured hello world!");
});
server.listen(43);

Refer to the Node.js tls.createServer() documentation for more information regarding the required key and cert configuration options.

While there are many details that still need to worked through, and likely many issues that need to be fixed… this initial implementation provides enough functionality to get started, including:

Push Stream Support

respondWithFile() and respondWithFD() APIs that allow extremely efficient sending of raw file data that bypasses the Streams API.

TLS and Plain-text connections

Full support for stream multiplexing

HTTP/2 Prioritization and Flow Control

Support for HTTP/2 trailers

HPACK header compression support

A compatibility API layer that operates as close as possible to the existing HTTP/1 API

Development will be ongoing, as will security hardening, performance optimization, and API refinement. The more input we get on this, the better it will become.

Happy Multiplexing to All :-)

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/84192.html

相關(guān)文章

  • [譯]當(dāng) Node.js Core 遇到 HTTP/2

    摘要:幾分鐘前我打開了一個,它為提供了初始的實(shí)現(xiàn)。雖然還不堪用,但對來說是一個重要的里程碑。首先你需要跟著這個介紹來配置好的構(gòu)建環(huán)境。我們付出的越多,就會變的越好。 原文:Say hello to HTTP/2 for Node.js Core 第一次嘗試翻譯文章,如果有翻譯的不好或者有錯誤的地方還望大佬們指點(diǎn)一二,謝謝。 幾分鐘前我打開了一個 pull-request,它為 Nodejs ...

    Yuanf 評論0 收藏0
  • 微服務(wù)框架 Spark Framework

    摘要:我是廣告本人的直播課程在月份就要開始了,希望小伙伴們支持一下,現(xiàn)在報(bào)名有優(yōu)惠噢 源碼:http://git.oschina.net/sancha... Spark Framework beetl fastjson 結(jié)合 項(xiàng)目結(jié)構(gòu)如下 showImg(https://segmentfault.com/img/bVP12A?w=315&h=512); pom.xml如下: 4...

    fasss 評論0 收藏0
  • Node.js原生開發(fā)入門完全教程

    摘要:原生開發(fā)入門完全教程微信公眾號開發(fā)企業(yè)級產(chǎn)品全棧開發(fā)速成周末班首期班號正式開班,歡迎搶座一關(guān)于本篇文章參考了入門并從零到壹操作了一遍,感謝原作者,同時也強(qiáng)烈推薦大家移步到原文給予原文作者一個贊賞支持。 Node.js原生開發(fā)入門完全教程 (Node+Vue+React+微信公眾號開發(fā))企業(yè)級產(chǎn)品全棧開發(fā)速成周末班首期班(10.28號正式開班,歡迎搶座) 一、關(guān)于 本篇文章參考了Node...

    alphahans 評論0 收藏0
  • 初識 CoffeeScript

    摘要:而造成一些莫名其妙的錯誤。寫一個文件打印出編譯命令會在同級目錄下生成一個同名的文件。將包裹在了一個匿名函數(shù)當(dāng)中,并用調(diào)用,這樣使得代碼隔離,不會和外部混淆。其中的表示的就是為了方便使用,可以使用雙冒號來替代。 很早就知道這CoffeeScript一門語言,但是一直沒有機(jī)會系統(tǒng)的學(xué)習(xí)下,那天趁在公司沒有什么要緊的項(xiàng)目做,就根據(jù)CoffeeScript首頁的例子學(xué)了一下。 引用Coffe...

    騫諱護(hù) 評論0 收藏0
  • node函數(shù)使用

    摘要:在中,一個函數(shù)可以作為另一個函數(shù)的參數(shù)。我們可以先定義一個函數(shù),然后傳遞,也可以在傳遞參數(shù)的地方直接定義函數(shù)。中函數(shù)的使用與類似。以上代碼中,我們把函數(shù)作為函數(shù)的第一個變量進(jìn)行了傳遞。 在JavaScript中,一個函數(shù)可以作為另一個函數(shù)的參數(shù)。我們可以先定義一個函數(shù),然后傳遞,也可以在傳遞參數(shù)的地方直接定義函數(shù)。 Node.js中函數(shù)的使用與Javascript類似。 funct...

    番茄西紅柿 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<