• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 14 years ago
  • Updated over 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

FastCGI protocol parser for node.js

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"
}

More Repositories

1

node-httpclient

a http client for node.js that handles https, cookies and gzip compression
JavaScript
69
star
2

ws-uv

websocket server using libuv
C
51
star
3

nodeftpd

node.js FTP Server
JavaScript
48
star
4

spindle

an(other) experimental JS runtime, this time with v8 fast api calls and auto-generated bindings
C++
42
star
5

node-memcache-parser

memcached binary protocol parser and encoder
JavaScript
22
star
6

node-gc

node module to expose access to V8 Garbage collection
C++
16
star
7

dv8

Minimalistic JS Runtime for V8 and libuv
C++
8
star
8

node-binary

binary packer and unpacker
JavaScript
8
star
9

f2d

experimental node.js web server
JavaScript
6
star
10

just-apps

miscellanous demo apps for just(js) framework
JavaScript
5
star
11

node-http-parser

attempt to improve http parsing performance in node.js
C
4
star
12

chartX

minimal real-time javascript canvas charting
JavaScript
4
star
13

just

tiny v8 javascript runtime for linux hackers
C++
3
star
14

mqsimple

simple mq client library for c/c++ with c# bindings
C++
3
star
15

node-zoneinfo

Tools for parsing and using tzinfo database
JavaScript
3
star
16

minode

minimal node.js - zero dependencies on builtin node javascript libs
JavaScript
3
star
17

swift-js

Javascript SWIFT (ISO15022) parsing library
JavaScript
3
star
18

minhttp

node.js minimal http addon
C
2
star
19

forkit

node.js clustering and keepalive daemon
JavaScript
2
star
20

deno-runtime-demo

demo deno based JS runtime for experimentation
Rust
2
star
21

tokamak

Small and Fast Socket and HTTP module for node.js
C++
1
star
22

dv8-examples

Examples for dv8 runtime
JavaScript
1
star