Giter VIP home page Giter VIP logo

http2.js's Introduction

http2.js

An HTTP/2 (RFC 7540) pure JavaScript client and server implementation for node.js.

npm version Build Status

Original Source and Fork intent

This NodeJS http2.js module version is a fork of node-http2 hosted on Github originally made by Gábor Molnár and available here: https://github.com/molnarg/node-http2

This fork of node-http2 module named http2.js starts at version 4.0.0 in case previous the repository decides to pick up work again on version 3.x.x.

We are aware that node 8.4.0 now has experimental http2 support via --expose-http2, and we will continue to support the full JavaScript implementation of http2.js at our discretion until HTTP/2 is more fully supported in a broad range of client platforms.

Installation

npm install http2.js

API

The API is very similar to the standard node.js HTTPS API. The goal is perfect API compatibility, with additional HTTP2 related extensions (like server push).

Detailed API documentation is primarily maintained in the lib/http.js file and is available in the wiki as well.

Examples

Using as a server

var options = {
  key: fs.readFileSync('./example/localhost.key'),
  cert: fs.readFileSync('./example/localhost.crt')
};

require('http2.js').createServer(options, function(request, response) {
  response.end('Hello world!');
}).listen(8080);

Using as a client

require('http2.js').get('https://localhost:8080/', function(response) {
  response.pipe(process.stdout);
});

Simple static file server

An simple static file server serving up content from its own directory is available in the example directory. Running the server:

$ node ./example/server.js

Simple command line client

An example client is also available. Downloading the server's own source code from the server:

$ node ./example/client.js 'https://localhost:8080/server.js' >/tmp/server.js

Server push

For a server push example, see the source code of the example server and client.

Status

  • ALPN is only supported in node.js >= 5.0
  • Upgrade mechanism to start HTTP/2 over unencrypted channel is not implemented yet (issue #4)
  • Other minor features found in this list are not implemented yet

Development

Development dependencies

There's a few library you will need to have installed to do anything described in the following sections. After installing/cloning node-http2, run npm install in its directory to install development dependencies.

Used libraries:

For pretty printing logs, you will also need a global install of bunyan (npm install -g bunyan).

Developer documentation

The developer documentation is generated from the source code using docco and can be viewed online here. If you'd like to have an offline copy, just run npm run-script doc.

Running the tests

It's easy, just run npm test. The tests are written in BDD style, so they are a good starting point to understand the code.

Test coverage

To generate a code coverage report, run npm test --coverage (which runs very slowly, be patient). Code coverage summary as of version 4.0.5:

Statements   : 89.51% ( 2031/2269 )
Branches     : 79.72% ( 861/1080 )
Functions    : 89.89% ( 240/267 )
Lines        : 89.55% ( 2023/2259 )

There's a hosted version of the detailed (line-by-line) coverage report here.

Logging

Logging is turned off by default. You can turn it on by passing a bunyan logger as log option when creating a server or agent.

When using the example server or client, it's very easy to turn logging on: set the HTTP2_LOG environment variable to fatal, error, warn, info, debug or trace (the logging level). To log every single incoming and outgoing data chunk, use HTTP2_LOG_DATA=1 besides HTTP2_LOG=trace. Log output goes to the standard error output. If the standard error is redirected into a file, then the log output is in bunyan's JSON format for easier post-mortem analysis.

Running the example server and client with info level logging output:

$ HTTP2_LOG=info node ./example/server.js
$ HTTP2_LOG=info node ./example/client.js 'https://localhost:8080/server.js' >/dev/null

Contributors

The co-maintainer of the project is Nick Hurley.

Code contributions are always welcome! People who contributed to node-http2 and http2.js so far:

Special thanks to Google for financing the development of this module as part of their Summer of Code program (project: HTTP/2 prototype server implementation), and Nick Hurley of Mozilla, my GSoC mentor, who helped with regular code review and technical advices.

License

The MIT License

Copyright (C) 2013 Gábor Molnár [email protected]

http2.js's People

Contributors

hthetiot avatar nwgh avatar jitsni avatar jscissr avatar felicienfrancois avatar thughes avatar argon avatar vsemogutor avatar simllll avatar philippsoehnlein avatar kesla avatar mikefrey avatar 890f2151c2be69c51db72017546d00fd avatar mortonfox avatar olemchls avatar mcmanus avatar mroutput avatar sdavis-r7 avatar sebdeckers avatar watson avatar avesus avatar oimou avatar ricordisamoa avatar julien-f avatar jfallows avatar jhen0409 avatar jstourac avatar snorp avatar ipetez avatar florianreinhart avatar

Stargazers

 avatar  avatar masx200 avatar Debdatta Basu avatar  avatar James Tan avatar Godpu avatar  avatar lkjx77 avatar nmccready avatar Mahesh avatar Davide De Gennaro avatar E_Bo avatar 文蔺 avatar 任侠 avatar Tomasz Jakut avatar Shahar Hadas avatar 333 avatar  avatar

Watchers

 avatar Benoit Marchant avatar James Cloos avatar Johnny Miller avatar Akram  Yakubov avatar lkjx77 avatar David Witherspoon avatar TenefitOps avatar  avatar  avatar  avatar Mike Dove avatar Tony Man avatar Daniel Smith avatar  avatar Sidda Eraiah avatar  avatar Avery Gottesman avatar Nick Zandbergen avatar Eric Jing Mockler avatar  avatar RD avatar

http2.js's Issues

Support for Cache-Digest (Server Push optimization)

Hi!

It would be nice if the Server Push implementation would support Cache-Digest. It will reduce both latency and bandwidth.

PerfPlanet.com TL;DR Without Cache Digests there is no clear-cut performance win for HTTP/2 Server Push over HTTP/1 Asset Bundling. However, a Bloom filter based technique, called Cache Digests, makes Server Push more efficient than Asset Bundling in both latency and bandwidth.

cache-digest

https://calendar.perfplanet.com/2016/cache-digests-http2-server-push/
http://httpwg.org/http-extensions/cache-digest.html
https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/

Error: stream.push() after EOF

Hi !
we have an issue with a post request to the avs cloud.
When we post the the first request with an outdated token we receive an 403 without error what is ok.

But when we send shortly after this a next request with the same outdated token we receive a 403 AND an unhandled error.
Sometimes also fails the first invalid request.
But the point is the unhandled error which crash our application.

// without error
WARN: [Http2Wrapper] sendMessage::start

DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST:: [ 'finish', 'response', 'error', 'socket' ]
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST socket event
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST finish event::resolve
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST response event:: [ 'end', 'prefinish', 'unpipe', 'drain', 'error', 'close', 'finish' ]
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST response event::statusCode:403

DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE data event:: chunk Unable to authenticate the request. Please provide a valid authorization token.
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE prefinish event
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE unpipe event
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE finish event
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE end event: statusCode:403

WARN: [Http2Wrapper] sendMessage::end with result { statusCode: 403 }

// SAME code with error
WARN: [Http2Wrapper] sendMessage::start

DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST:: [ 'finish', 'response', 'error', 'socket' ]
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST socket event
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST finish event::resolve
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST response event:: [ 'end', 'prefinish', 'unpipe', 'drain', 'error', 'close', 'finish' ]
DEBUG: [Http2Wrapper] sendMessage::R-1::REQUEST response event::statusCode:403

DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE data event:: chunk Unable to authenticate the request. Please provide a valid authorization token.
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE prefinish event
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE unpipe event
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE finish event
DEBUG: [Http2Wrapper] sendMessage::R-1::RESPONSE end event: statusCode:403

WARN: [Http2Wrapper] sendMessage::end with result { statusCode: 403 }
Error: stream.push() after EOF
at readableAddChunk (_stream_readable.js:240:30)
at Connection.Readable.push (_stream_readable.js:208:10)
at Connection._parentPush (D:\Work2018\vw.devel\iav.mib3.vw.alexa\addons\webapps\background\node_modules\http2.js\lib\protocol\flow.js:245:32)
at Connection._push (D:\Work2018\vw.devel\iav.mib3.vw.alexa\addons\webapps\background\node_modules\http2.js\lib\protocol\flow.js:257:17)
at Connection.push (D:\Work2018\vw.devel\iav.mib3.vw.alexa\addons\webapps\background\node_modules\http2.js\lib\protocol\flow.js:288:23)
at Connection._restoreWindow (D:\Work2018\vw.devel\iav.mib3.vw.alexa\addons\webapps\background\node_modules\http2.js\lib\protocol\flow.js:117:10)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)

HEADERs encoding issue

HEADERS frame is encoded incorrectly sometimes. It looks like some of the headers content is messed up. I can give a hex dump of the HEADERS frame.

How do I customize headers?

Under the case ,how to write? thanks very much

:authority:xxx.XXX.com
:method:POST
:path:/api/web/v1/orders
:scheme:https
accept:application/json, text/plain, /
accept-encoding:gzip, deflate, br
accept-language:zh-CN,zh;q=0.8
content-length:71
content-type:application/json;charset=UTF-8
cookie:__zlcmid=nShV2s2YoK74QV; gpm-caveat=y; prd-token="ddd-n4Q=="; u=aaa; _gat=1; _ga=GA1.2.sss.eee; _gid=GA1.2.sss.eee
origin:https://xxx.XXX.com
referer:https://xxx.XXX.com/ex/gpm/xxx
token:ddd-n4Q==
user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0

Fork as 'http2.js' and import fixes from legacy repository

Original Source and Fork intent

This NodeJS http2.js module version is a fork of node-http2 hosted on Github originally made by Gábor Molnár and available here: https://github.com/molnarg/node-http2

This fork of node-http2 module named http2.js starts at version 4.0.0 in case previous the repository decides to pick up work again on version 3.x.x.

We are aware that node 8.4.0 now has experimental http2 support via --expose-http2, and we will continue to support the full JavaScript implementation of http2.js at our discretion until HTTP/2 is more fully supported in a broad range of client platforms.

Changes:

4.0.1 (2017-10-01)

  • Bugfixes from pull requests
    • Fails to load in IE11 due to timers.setImmediate call
    • Fix Node 5+ support #4 bug
    • update object-keys module for Object.keys shim

4.0.0 (2017-08-23)

Considering

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.