phoenixsol / lua-http-parser forked from ry/http-parser

Lua binding to Ryan Dahl's http request/response parser.

This URL has Read+Write access

name age message
file LICENSE-MIT Mon Nov 30 10:53:06 -0800 2009 eats kittens [phoenixsol]
file Makefile Mon Nov 30 10:53:06 -0800 2009 eats kittens [phoenixsol]
file README.md Wed Dec 09 06:09:54 -0800 2009 Merge branch 'master' of git://github.com/ry/ht... [phoenixsol]
directory http_parser/ Wed Dec 09 06:09:54 -0800 2009 Merge branch 'master' of git://github.com/ry/ht... [phoenixsol]
file lua_binding.c Mon Nov 30 10:53:06 -0800 2009 eats kittens [phoenixsol]
file test.lua Mon Nov 30 10:59:49 -0800 2009 touchup test.lua [phoenixsol]
README.md

HTTP Parser

This is a parser for HTTP messages written in C. It parses both requests and responses. The parser is designed to be used in performance HTTP applications. It does not make any allocations, it does not buffer data, and it can be interrupted at anytime. It only requires about 136 bytes of data per message stream (in a web server that is per connection).

Features:

  • No dependencies
  • Parses both requests and responses.
  • Handles persistent streams.
  • Decodes chunked encoding.
  • Extracts the following data from a message
    • header fields and values
    • content-length
    • request method
    • response status code
    • transfer-encoding
    • http version
    • request path, query string, fragment
    • message body
  • Defends against buffer overflow attacks.

Lua Binding

Aims to be minimal and flexible; Allows setting of all parser callbacks from Lua.

local HTTPParser = require 'httpparser'

local parser = HTTPParser.new()

function parser.on_uri(data) print(data) end
function parser.on_path(data) print(data) end

parser:parse_request(request_data)
--parser:parse_response(response_data)

Return non-zero in the parser callbacks to stop the parser.

See 'test.lua' for a more complete example.