npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cheath2.js

v1.2.2

Published

[![Build Status](https://travis-ci.org/andham97/cheat-h2.js.svg?branch=master)](https://travis-ci.org/andham97/cheat-h2.js) [![codecov](https://codecov.io/gh/andham97/cheat-h2.js/branch/master/graph/badge.svg)](https://codecov.io/gh/andham97/cheat-h2.js)

Downloads

9

Readme

cheat-h2.js

"It so simple it feels like cheating"

Build Status codecov

A HTTP/2 implementation for Node.js conforming to RFC7540 and RFC7541

Implemented functionality

  1. TLS
  2. Connection preface
  3. Datawrapper from frames
  4. Headercompression with hpack
  5. Flow control
  6. Stream priority
  7. Error handling
  8. Connection management
  9. Cross protocols attach
  10. Error handling
  11. Stream prioritization and concurrency
  12. Server push (beta)

TODO

  1. Implement all HTTP header fields
  2. Connect method see section 10.3
  3. DOS security see section 10.5
  4. Server authority see section 10.1
  5. IE attach see section 10.3
  6. Make logging optional

Installation

cheat-h2.js is available through the NPM registry.

Before installing note that Node.js 9.3.0 or higher is required.

Installation is done using the npm install command:

$ npm install cheath2.js

Usage

import cheath2 from 'cheath2.js';
import fs from 'fs';

let server = new cheath2({
  key: fs.readFileSync('<directory of private-key>'),
  cert: fs.readFileSync('<directory of public-cert>')
});

server.get('/', (req, res) => {
  res.headers['content-encoding'] = 'text/plain';
  res.status(200).send('Hello world!');
});

server.listen(8000);

Tests

While inside the project directory run:

$ npm install --dev
$ npm test

API documentation

Class:http2

  • key: stores the PEM formatted private key
  • cert: stores the PEM formatted public certificate
  • server: stores the instance of the TLS server

new http2([options])

Initiate a new TLS server with the provided key and certificate

  • options
    • key: Buffer containing private key in PEM format
    • cert: Buffer containing public certificate in PEM format

http2.listen(port)

Start the server listening for encrypted connections on port

http2.use(path, handler)

  • path: String representing the url to register the handler to
  • handler: Function the request handler function that will be invoked when the provided path is requested

handler has the signature (request, response, next)

http2.use(handler)

  • handler: Function the middleware function, invoked on every request

handler has the signature (request, response, next)

http2.get(path, handler)

  • path: String representing the url to register the GET handler to
  • handler: Function the request handler function that will be invoked when the provided path is requested using the GET method

handler has the signature (request, response, next)

http2.post(path, handler)

  • path: String representing the url to register the POST handler to
  • handler: Function the request handler function that will be invoked when the provided path is requested using the POST method

handler has the signature (request, response, next)

next parameter in handler methods

The next parameter is a Function with the signature (request, response, next) invoking the next matching request handler

Class:Request

  • headers: Object containing the different header fields in the request
  • raw_data: Buffer containing the raw data received from the client
  • query: Object containing the GET query
  • body: Object containing the query from the body
server.get('/', (request, response, next) => {
  let method = request.headers[':method'];
  if(method == 'GET')
    console.log(request.query);
  else
    console.log(request.body);
});

new Request(headers, data)

  • headers: Array of request header fields represented as an Array structured as [[key, value], [key, value]...]
  • data: Buffer containing the raw data from the request

Class:Response

  • headers: Array of response header fields represented as an Array structured as [[key, value], [key, value]...]
  • payload: Buffer containing the raw data to respond to the client
  • is_sent: Boolean storing if the response is sent already (true if sent)
  • required_paths: Array storing paths specified for server push

new Response()

Set up a basic Response object containing content-type and content-length headers

response.status(code)

  • code: Number representing the status code to be sent to the client

Stores the status code in headers

response.send(data)

  • data: Buffer or String to be sent to the client

Stores the data in the payload and prevents the response to be "sent" again

response.sendFile(path)

  • path: String holding the path to the file to transmit

Reads the file at the path location to payload and prevents the response to be "sent" again

response.push(path)

  • path: Object structure: {method: '', path: ''} Registers the path as a HTTP/2 Push so the library utilises HTTP/2 Push to serve the data. This can be registered multiple times for multiple dependecies to be pushed to the client
server.get('/', (request, response, next) => {
  response.sendFile(__dirname + '/public/index.html');
  response.push({
    method: 'GET',
    path: '/index.css'
  });
  response.push({
    method: 'GET',
    path: '/index.js'
  });
});

server.get('/index.js', (request, response, next) => {
  response.sendFile(__dirname + '/public/index.js');
});

server.get('/index.css', (request, response, next) => {
  response.sendFile(__dirname + '/public/index.css');
});