JSPM

  • Created
  • Published
  • Downloads 10994213
  • Score
    100M100P100Q226002F
  • License MIT

Use HTTP2 the same way like HTTP1

Package Exports

  • http2-wrapper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (http2-wrapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

http2-wrapper

Use HTTP2 the same way like HTTP1

Usage

'use strict';
const http2 = require('http2-wrapper');

const options = {
    hostname: 'nghttp2.org',
    protocol: 'https:',
    path: '/httpbin/post',
    method: 'POST',
    headers: {
        'content-length': 6
    }
};

const req = http2.request(options, res => {
    console.log('statusCode:', res.statusCode);
    console.log('headers:', res.headers);

    const body = [];
    res.on('data', chunk => {
        body.push(chunk);
    });
    res.on('end', () => {
        console.log('body:', Buffer.concat(body).toString());
    });
});

req.on('error', e => console.error(e));

req.write('123');
req.end('456');

// statusCode: 200
// headers: { ':status': 200,
//   date: 'Sat, 11 Aug 2018 09:37:41 GMT',
//   'content-type': 'application/json',
//   'content-length': '264',
//   'access-control-allow-origin': '*',
//   'access-control-allow-credentials': 'true',
//   'x-backend-header-rtt': '0.002997',
//   'strict-transport-security': 'max-age=31536000',
//   server: 'nghttpx',
//   via: '1.1 nghttpx',
//   'x-frame-options': 'SAMEORIGIN',
//   'x-xss-protection': '1; mode=block',
//   'x-content-type-options': 'nosniff' }
// body: {
//   "args": {},
//   "data": "123456",
//   "files": {},
//   "form": {},
//   "headers": {
//     "Content-Length": "6",
//     "Host": "nghttp2.org:443",
//     "Via": "2 nghttpx"
//   },
//   "json": 123456,
//   "origin": "xxx.xxx.xxx.xxx",
//   "url": "https://nghttp2.org:443/httpbin/post"
// }

TODO

HTTP2IncomingMessage

  • Event: 'aborted'
  • Event: 'close'
  • message.destroy([error])
  • message.headers
  • message.httpVersion
  • message.rawHeaders
  • message.rawTrailers
  • message.setTimeout(msecs, callback)
  • message.socket
  • message.statusCode
  • message.statusMessage
  • message.trailers

HTTP2ClientRequest

  • Event: 'abort'
  • Event: 'connect'
  • Event: 'continue'
  • Event: 'information'
  • Event: 'response'
  • Event: 'socket'
  • Event: 'timeout'
  • Event: 'upgrade'
  • request.abort()
  • request.aborted
  • request.connection
  • request.end([data[, encoding]][, callback])
  • request.flushHeaders()
  • request.getHeader(name)
  • request.removeHeader(name)
  • request.setHeader(name, value)
  • request.setNoDelay([noDelay])
  • request.setSocketKeepAlive([enable][, initialDelay])
  • request.setTimeout(timeout[, callback])
  • request.socket
  • request.write(chunk[, encoding][, callback])