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

fastcgi-parser

v0.1.5

Published

FastCGI parser for low level parsing of the FastCGI protocol

Downloads

291

Readme

FastCGI Parser for Node.js

A very basic FastCGI parser for low level parsing of the FastCGI protocol. Can be used to build FastCGI applications which are called from an existing web server (nginx/lighttpd/apache etc.) or to interact with FastCGI applications.

Dependencies

  • currently using creatonix's buffer_extras module for binary packing. this will be replaced by a more efficient c++ addon or i might make the binary packing/unpacking pluggable

Todo

Usage (see tests/test.js)

Server Configuration

Lighttpd

fastcgi.server = ( ".js" =>
	( "localhost" =>
		(
			"socket" => "/tmp/nginx.sock",
			"check-local" => "disable"
		)
	)
)

nginx

location ~ \.js$ {
	fastcgi_pass   unix:/tmp/nginx.sock;
	fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
}

API

fastcgi.parser

parser.encoding = ["utf8"|"ascii"|"binary"]

default is utf8. this determines the encoding used when reading the body of an STDIN/STDOUT/STDERR record. utf8 or ascii mean no onBody callback will be fired and the record in onRecord will have a body property set to the correctly encoded string. binary will mean no body property is set on the record returned in the onRecord callback and chunks of the body will be emitted in the onBody callback as they arrive.

parser.reset = function()

resets the parser so it can be executed on a new stream. you should use this aftaer an error or when re-using an already existing parser on a new stream.

parser.init = function()

completely reinitialises the parser. calls parser.reset as well as setting encoding back to default (utf8) and clearing all callback handlers

parser.execute = function(buffer)

parses the buffer. calls callback.

fastcgi.constants

"version": 1,
"record": {
	"FCGI_BEGIN": 1,
	"FCGI_ABORT": 2,
	"FCGI_END": 3,
	"FCGI_PARAMS": 4,
	"FCGI_STDIN": 5,
	"FCGI_STDOUT": 6,
	"FCGI_STDERR": 7,
	"FCGI_DATA": 8,
	"FCGI_GET_VALUES": 9,
	"FCGI_GET_VALUES_RESULT": 10,
	"FCGI_UNKNOWN_TYPE": 11
},
"keepalive": {
	"OFF": 0,
	"ON": 1
},
"parser": {
	"state": {
		"HEADER": 0,
		"BODY": 1,
		"PADDING": 2
	}
},
"general": {
	"FCGI_HEADER_LEN": 8,
	"FCGI_MAX_BODY": Math.pow(2,16)
},
"errors": {
	"BUFFER_OVERFLOW": {
		"err": 1,
		"description": "buffer overflow"
	},
	"MAX_BODY_EXCEEDED": {
		"err": 2,
		"description": "a body greater than maximum body size was read/written"
	}
},
"flags": {
	"FCGI_KEEP_CONN": 1
},
"role": {
	"FCGI_RESPONDER": 1,
	"FCGI_AUTHORIZER": 2,
	"FCGI_FILTER": 3
},
"protocol": {
	"status": {
		"FCGI_REQUEST_COMPLETE": 0,
		"FCGI_CANT_MPX_CONN": 1,
		"FCGI_OVERLOADED": 2,
		"FCGI_UNKNOWN_ROLE": 3
	}
},
"values": {
	"FCGI_MAX_CONNS": "FCGI_MAX_CONNS",
	"FCGI_MAX_REQS": "FCGI_MAX_REQS",
	"FCGI_MPXS_CONNS": "FCGI_MPXS_CONNS"
}