Sha256: e962a59d0562d40b221e68619eb8ec414eeb192940b34e466107404ef3f141e4

Contents?: true

Size: 988 Bytes

Versions: 4

Compression:

Stored size: 988 Bytes

Contents

# http_parser.rb

A simple callback-based HTTP request/response parser for writing http
servers, clients and proxies.

This gem is built on top of [ry/http-parser](http://github.com/ry/http-parser) and its java port [a2800276/http-parser.java](http://github.com/a2800276/http-parser.java).

## Supported Platforms

This gem aims to work on all major Ruby platforms, including:

- MRI 1.8 and 1.9
- Rubinius
- JRuby
- win32

## Usage

    require "http/parser"

    parser = Http::Parser.new

    parser.on_headers_complete = proc do |headers|
      p parser.http_method
      p parser.http_version

      p parser.request_url # for requests
      p parser.status_code # for responses

      p headers
    end

    parser.on_body = proc do |chunk|
      # One chunk of the body
      p chunk
    end

    parser.on_message_complete = proc do |env|
      # Headers and body is all parsed
      puts "Done!"
    end

    # Feed raw data from the socket to the parser
    parser << raw_data

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
http_parser.rb-0.5.0 README.md
http_parser.rb-0.5.0-x86-mswin32-60 README.md
http_parser.rb-0.5.0-x86-mingw32 README.md
http_parser.rb-0.5.0-java README.md