http-parser-lite 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/README.md +77 -0
- data/ext/http-parser/extconf.rb +4 -0
- data/ext/http-parser/http_parser.c +2059 -0
- data/ext/http-parser/http_parser.h +318 -0
- data/ext/http-parser/ruby_http_parser.c +131 -0
- data/lib/http-parser.rb +18 -0
- data/test/helper.rb +2 -0
- data/test/test_http_parser.rb +50 -0
- metadata +72 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'http-parser' do
|
4
|
+
attr_reader :parser
|
5
|
+
|
6
|
+
before do
|
7
|
+
@parser = HTTP::Parser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should parse request' do
|
11
|
+
got = []
|
12
|
+
parser.on_url {|data| got << data}
|
13
|
+
parser.on_header_field {|data| got << data}
|
14
|
+
parser.on_header_value {|data| got << data}
|
15
|
+
|
16
|
+
parser << "GET http://www.google.com HTTP/1.1\r\nX-Test-Key: 1\r\n\r\n"
|
17
|
+
assert_equal %w(http://www.google.com X-Test-Key 1), got
|
18
|
+
assert_equal 'GET', parser.http_method
|
19
|
+
assert_equal '1.1', parser.http_version
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should parse response' do
|
23
|
+
got = []
|
24
|
+
parser.on_url {|data| got << data}
|
25
|
+
parser.on_header_field {|data| got << data}
|
26
|
+
parser.on_header_value {|data| got << data}
|
27
|
+
parser.on_body {|data| got << data}
|
28
|
+
parser << "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 5\r\n\r\nhello"
|
29
|
+
|
30
|
+
assert_equal %w(Content-Type text/plain Content-Length 5 hello), got
|
31
|
+
assert_equal '1.1', parser.http_version
|
32
|
+
assert_equal 200, parser.http_status
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should parse CONNECT' do
|
36
|
+
got = []
|
37
|
+
parser.on_url {|data| got << data}
|
38
|
+
parser.on_header_field {|data| got << data}
|
39
|
+
parser.on_header_value {|data| got << data}
|
40
|
+
parser << "CONNECT 345.example.com:443 HTTP/1.1\r\nUser-Agent: X-Test-UA\r\n\r\n"
|
41
|
+
|
42
|
+
assert_equal %w(345.example.com:443 User-Agent X-Test-UA), got
|
43
|
+
assert_equal 'CONNECT', parser.http_method
|
44
|
+
assert_equal '1.1', parser.http_version
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should raise an error on invalid data' do
|
48
|
+
assert_raises(HTTP::ParserError) { parser << "GET / foobar\r\n" }
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-parser-lite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bharanee Rathna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A lite ruby wrapper around Joyent http-parser
|
31
|
+
email:
|
32
|
+
- deepfryed@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions:
|
35
|
+
- ext/http-parser/extconf.rb
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- ext/http-parser/http_parser.c
|
39
|
+
- ext/http-parser/ruby_http_parser.c
|
40
|
+
- ext/http-parser/http_parser.h
|
41
|
+
- ext/http-parser/extconf.rb
|
42
|
+
- test/helper.rb
|
43
|
+
- test/test_http_parser.rb
|
44
|
+
- lib/http-parser.rb
|
45
|
+
- README.md
|
46
|
+
- CHANGELOG
|
47
|
+
homepage: http://github.com/deepfryed/http-parser-lite
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
- ext
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.24
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Simple wrapper around Joyent http-parser
|
72
|
+
test_files: []
|