yakischloba-http-parser 0.0.2 → 0.0.3
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/http-parser.gemspec +2 -2
- data/lib/http-parser.rb +53 -19
- data/test/request.rb +24 -1
- data/test/response.rb +21 -1
- metadata +2 -2
data/http-parser.gemspec
CHANGED
data/lib/http-parser.rb
CHANGED
@@ -7,25 +7,27 @@ class HttpParser
|
|
7
7
|
callback :http_data_cb, [:pointer, :pointer, :size_t], :int
|
8
8
|
callback :http_cb, [:pointer], :int
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
10
|
+
METHODS = {
|
11
|
+
0x0001 => :COPY,
|
12
|
+
0x0002 => :DELETE,
|
13
|
+
0x0004 => :GET,
|
14
|
+
0x0008 => :HEAD,
|
15
|
+
0x0010 => :LOCK,
|
16
|
+
0x0020 => :MKCOL,
|
17
|
+
0x0040 => :MOVE,
|
18
|
+
0x0080 => :OPTIONS,
|
19
|
+
0x0100 => :POST,
|
20
|
+
0x0200 => :PROPFIND,
|
21
|
+
0x0400 => :PROPPATCH,
|
22
|
+
0x0800 => :PUT,
|
23
|
+
0x1000 => :TRACE,
|
24
|
+
0x2000 => :UNLOCK
|
25
|
+
}
|
26
|
+
|
27
|
+
ENCODINGS = {
|
28
|
+
0x01 => :IDENTITY,
|
29
|
+
0x02 => :CHUNKED
|
30
|
+
}
|
29
31
|
|
30
32
|
enum :http_parser_type, [:HTTP_REQUEST, :HTTP_RESPONSE]
|
31
33
|
|
@@ -100,6 +102,38 @@ class HttpParser
|
|
100
102
|
@abort = true
|
101
103
|
end
|
102
104
|
|
105
|
+
def method
|
106
|
+
METHODS[@parser[:method]]
|
107
|
+
end
|
108
|
+
|
109
|
+
def status_code
|
110
|
+
@parser[:status_code]
|
111
|
+
end
|
112
|
+
|
113
|
+
def transfer_encoding
|
114
|
+
ENCODINGS[@parser[:transfer_encoding]]
|
115
|
+
end
|
116
|
+
|
117
|
+
def version_major
|
118
|
+
@parser[:version_major]
|
119
|
+
end
|
120
|
+
|
121
|
+
def version_minor
|
122
|
+
@parser[:version_minor]
|
123
|
+
end
|
124
|
+
|
125
|
+
def version
|
126
|
+
[version_major, version_minor]
|
127
|
+
end
|
128
|
+
|
129
|
+
def content_length
|
130
|
+
@parser[:content_length]
|
131
|
+
end
|
132
|
+
|
133
|
+
def keep_alive?
|
134
|
+
@parser[:keep_alive].zero? ? false : true
|
135
|
+
end
|
136
|
+
|
103
137
|
def on_message_begin(proc=nil, &blk)
|
104
138
|
proc ||= blk
|
105
139
|
@on_message_begin = Proc.new do |ptr|
|
data/test/request.rb
CHANGED
@@ -35,7 +35,15 @@ describe "http-parser request parsing" do
|
|
35
35
|
@parser.on_header_field {|f| @current_field = f }
|
36
36
|
@parser.on_header_value {|v| @headers[@current_field] = v }
|
37
37
|
@parser.on_headers_complete { @headers_complete = true }
|
38
|
-
@parser.on_message_complete
|
38
|
+
@parser.on_message_complete do
|
39
|
+
@message_complete = true
|
40
|
+
@content_length = @parser.content_length
|
41
|
+
@status_code = @parser.status_code
|
42
|
+
@method = @parser.method
|
43
|
+
@version = @parser.version
|
44
|
+
@keep_alive = @parser.keep_alive?
|
45
|
+
@encoding = @parser.transfer_encoding
|
46
|
+
end
|
39
47
|
@parser.execute(REQUEST_BUFFER)
|
40
48
|
|
41
49
|
it "calls back when beginning a message" do
|
@@ -62,6 +70,21 @@ describe "http-parser request parsing" do
|
|
62
70
|
@headers_complete.should.equal true
|
63
71
|
end
|
64
72
|
|
73
|
+
it "makes the method/version/keepalive/encoding available after headers are parsed" do
|
74
|
+
@method.should.equal :GET
|
75
|
+
@version.should.equal [1,1]
|
76
|
+
@keep_alive.should.equal true
|
77
|
+
@encoding.should.equal :IDENTITY
|
78
|
+
end
|
79
|
+
|
80
|
+
it "has a 0 status code since its a request" do
|
81
|
+
@status_code.should.equal 0
|
82
|
+
end
|
83
|
+
|
84
|
+
it "has a 0 content_length since we have no body" do
|
85
|
+
@content_length.should.equal 0
|
86
|
+
end
|
87
|
+
|
65
88
|
it "calls back when parsing of the message is complete" do
|
66
89
|
@message_complete.should.equal true
|
67
90
|
end
|
data/test/response.rb
CHANGED
@@ -36,7 +36,15 @@ describe "http-parser response parsing" do
|
|
36
36
|
@parser.on_message_begin { @message_begun = true }
|
37
37
|
@parser.on_header_field {|f| @current_field = f }
|
38
38
|
@parser.on_header_value {|v| @headers[@current_field] = v }
|
39
|
-
@parser.on_headers_complete
|
39
|
+
@parser.on_headers_complete do
|
40
|
+
@headers_complete = true
|
41
|
+
@method = @parser.method
|
42
|
+
@version = @parser.version
|
43
|
+
@status_code = @parser.status_code
|
44
|
+
@encoding = @parser.transfer_encoding
|
45
|
+
@content_length = @parser.content_length
|
46
|
+
@keep_alive = @parser.keep_alive?
|
47
|
+
end
|
40
48
|
@parser.on_body {|b| @body = b }
|
41
49
|
@parser.on_message_complete { @message_complete = true }
|
42
50
|
@parser.execute(RESPONSE_BUFFER)
|
@@ -53,6 +61,18 @@ describe "http-parser response parsing" do
|
|
53
61
|
@headers_complete.should.equal true
|
54
62
|
end
|
55
63
|
|
64
|
+
it "makes the version/status code/encoding/content length/keepalive available after headers are parsed" do
|
65
|
+
@version.should.equal [1,1]
|
66
|
+
@status_code.should.equal 200
|
67
|
+
@encoding.should.equal :IDENTITY
|
68
|
+
@content_length.should.equal 17
|
69
|
+
@keep_alive.should.equal false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "has a nil method since it's a response" do
|
73
|
+
@method.should.equal nil
|
74
|
+
end
|
75
|
+
|
56
76
|
it "calls back with the body" do
|
57
77
|
@body.should.equal RESPONSE_BODY
|
58
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yakischloba-http-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Dahl
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-08-
|
14
|
+
date: 2009-08-08 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|