33
GitHub - szmarczak/http2-wrapper: Use HTTP2 the same way like HTTP1
source link: https://github.com/szmarczak/http2-wrapper
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
http2-wrapper (under heavy development)
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.maxHeadersCount
- 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])
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK