Project

http_tools

0.1
No commit activity in last 3 years
No release in over 3 years
A fast-as-possible pure Ruby HTTP parser plus associated lower level utilities to aid working with HTTP and the web.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

HTTPTools is a collection of lower level utilities to aid working with HTTP, including a fast-as-possible pure Ruby HTTP parser.

Platform Support¶ ↑

Written purely in Ruby, with no dependencies outside of the standard library, it should run across all Ruby implementations compatible with 1.8 or later, and install in environments without a compiler available.

Tests are currently run on travis-ci against Ruby 1.8.7, 1.9.2, 1.9.3, JRuby, Rubinius, and Ruby Enterprise Edition. Additionally tests are run against 1.8.6 and MacRuby

Performance tuning is mainly aimed at Ruby 1.9, with Ruby 1.8 and JRuby taken in to consideration. JRuby is generally fastest.

HTTPTools::Parser¶ ↑

HTTPTools::Parser is a HTTP request & response parser with an evented API. Despite being just Ruby, every effort has been made to ensure it is as fast as possible.

Example¶ ↑

parser = HTTPTools::Parser.new
parser.on(:header) do
  puts parser.status_code.to_s + " " + parser.message
  puts parser.header.inspect
end
parser.on(:finish) {print parser.body}

parser << "HTTP/1.1 200 OK\r\n"
parser << "Content-Length: 20\r\n\r\n"
parser << "<h1>Hello world</h1>"

Prints:

200 OK
{"Content-Length" => "20"}
<h1>Hello world</h1>

HTTPTools::Encoding¶ ↑

HTTPTools::Encoding provides methods to deal with several HTTP related encodings including url, www-form, and chunked transfer encoding. It can be used as a mixin or class methods on HTTPTools::Encoding.

Example¶ ↑

HTTPTools::Encoding.www_form_encode({"query" => "fish", "lang" => "en"})
#=> "query=fish&lang=en"

include HTTPTools::Encoding
www_form_decode("lang=en&query=fish")
#=> {"lang" => "en", "query" => "fish"}

HTTPTools::Builder¶ ↑

HTTPTools::Builder is a provides a simple interface to build HTTP requests & responses. It can be used as a mixin or class methods on HTTPTools::Builder.

Example¶ ↑

Builder.request(:get, "example.com")
#=> "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"

Licence¶ ↑

(The MIT License)

Copyright © 2012, 2011 Matthew Sadler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.