http-parser 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/ext/http-parser/http_parser.c +11 -1
- data/ext/http-parser/http_parser.h +9 -9
- data/lib/http-parser/parser.rb +19 -10
- data/lib/http-parser/version.rb +1 -1
- data/spec/parser_spec.rb +25 -0
- metadata +33 -40
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ODNiNzNmM2Q3ZjE4Mjk1NzFiMDQ5ZDM3YTUxNGM5OGVlNWI3MWMzMzQ5NjIx
|
10
|
-
NGQ0YTYyYzYyNDZhOTE4NTZkMGYxZjY3ZjllMzViZGY0Nzk3NDM0NmFjYTll
|
11
|
-
YzI3NjFiOGJiNjI0MmFmZDc4NjJkOTI0YmFlNjkwMmM5NDVmYmU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Nzc3MTM3ZTc2ZTJjMzYxZThmY2IzMTJlMWQzZGU4MjIyZDNkODMyN2RmNWE2
|
14
|
-
OTNkYzYzMTM1MjM1MjMyOTUxZDkzY2VjMzk4YzU4NTZmMTQ2ODQwOWZkMWVj
|
15
|
-
ZmIyM2Q4MzkwN2Y4NmY5OTJkZGIyNTI0MTUyZWZkYzQ5ZDQxMWQ=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ee24befc2a0a23054f11edb4379b9b6b1f8d21a
|
4
|
+
data.tar.gz: 816280693464c8c5daa1c7fb20fe4954c3dd1a26
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1846519857ad32e3f688cf18f28fb3dd2cd33fa4c0a0909d6a2c934218b1ae5df30101b54a8b100cb8caaf28482a964e8e17ef5594abc91fddcb575d67ac5091
|
7
|
+
data.tar.gz: 82c5dba81e1673ab22497e5e1adda9d6f89ab115795747bc64a0043ced1511880c65d003b379a4f35e89976d92bdf793933bf196b2002876edb431f2c2dcc4c6
|
@@ -634,7 +634,17 @@ size_t http_parser_execute (http_parser *parser,
|
|
634
634
|
|
635
635
|
if (PARSING_HEADER(parser->state)) {
|
636
636
|
++parser->nread;
|
637
|
-
/*
|
637
|
+
/* Don't allow the total size of the HTTP headers (including the status
|
638
|
+
* line) to exceed HTTP_MAX_HEADER_SIZE. This check is here to protect
|
639
|
+
* embedders against denial-of-service attacks where the attacker feeds
|
640
|
+
* us a never-ending header that the embedder keeps buffering.
|
641
|
+
*
|
642
|
+
* This check is arguably the responsibility of embedders but we're doing
|
643
|
+
* it on the embedder's behalf because most won't bother and this way we
|
644
|
+
* make the web a little safer. HTTP_MAX_HEADER_SIZE is still far bigger
|
645
|
+
* than any reasonable request or response so this should never affect
|
646
|
+
* day-to-day operation.
|
647
|
+
*/
|
638
648
|
if (parser->nread > HTTP_MAX_HEADER_SIZE) {
|
639
649
|
SET_ERRNO(HPE_HEADER_OVERFLOW);
|
640
650
|
goto error;
|
@@ -193,11 +193,11 @@ enum http_errno {
|
|
193
193
|
|
194
194
|
struct http_parser {
|
195
195
|
/** PRIVATE **/
|
196
|
-
unsigned
|
197
|
-
unsigned
|
198
|
-
unsigned
|
199
|
-
unsigned
|
200
|
-
unsigned
|
196
|
+
unsigned int type : 2; /* enum http_parser_type */
|
197
|
+
unsigned int flags : 6; /* F_* values from 'flags' enum; semi-public */
|
198
|
+
unsigned int state : 8; /* enum state from http_parser.c */
|
199
|
+
unsigned int header_state : 8; /* enum header_state from http_parser.c */
|
200
|
+
unsigned int index : 8; /* index into current matcher */
|
201
201
|
|
202
202
|
uint32_t nread; /* # bytes read in various scenarios */
|
203
203
|
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
|
@@ -205,16 +205,16 @@ struct http_parser {
|
|
205
205
|
/** READ-ONLY **/
|
206
206
|
unsigned short http_major;
|
207
207
|
unsigned short http_minor;
|
208
|
-
unsigned
|
209
|
-
unsigned
|
210
|
-
unsigned
|
208
|
+
unsigned int status_code : 16; /* responses only */
|
209
|
+
unsigned int method : 8; /* requests only */
|
210
|
+
unsigned int http_errno : 7;
|
211
211
|
|
212
212
|
/* 1 = Upgrade header was present and the parser has exited because of that.
|
213
213
|
* 0 = No upgrade header present.
|
214
214
|
* Should be checked when http_parser_execute() returns in addition to
|
215
215
|
* error checking.
|
216
216
|
*/
|
217
|
-
unsigned
|
217
|
+
unsigned int upgrade : 1;
|
218
218
|
|
219
219
|
/** PUBLIC **/
|
220
220
|
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
data/lib/http-parser/parser.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
module HttpParser
|
3
3
|
class Parser
|
4
|
+
CALLBACKS = [:on_message_begin, :on_url, :on_status_complete, :on_header_field, :on_header_value, :on_headers_complete, :on_body, :on_message_complete]
|
5
|
+
|
4
6
|
#
|
5
7
|
# Returns a new request/response instance variable
|
6
8
|
#
|
@@ -12,9 +14,16 @@ module HttpParser
|
|
12
14
|
#
|
13
15
|
# Initializes the Parser instance.
|
14
16
|
#
|
15
|
-
def initialize
|
17
|
+
def initialize(callback_obj = nil)
|
16
18
|
@settings = ::HttpParser::Settings.new
|
17
19
|
@callbacks = {} # so GC doesn't clean them up on java
|
20
|
+
|
21
|
+
if not callback_obj.nil?
|
22
|
+
CALLBACKS.each do |callback|
|
23
|
+
self.__send__(callback, &callback_obj.method(callback)) if callback_obj.respond_to? callback
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
18
27
|
yield self if block_given?
|
19
28
|
end
|
20
29
|
|
@@ -24,7 +33,7 @@ module HttpParser
|
|
24
33
|
# @yield [instance]
|
25
34
|
# The given block will be called when the HTTP message begins.
|
26
35
|
#
|
27
|
-
# @yieldparam [
|
36
|
+
# @yieldparam [HttpParser::Instance] instance
|
28
37
|
# The state so far of the request / response being processed.
|
29
38
|
#
|
30
39
|
def on_message_begin(&block)
|
@@ -40,7 +49,7 @@ module HttpParser
|
|
40
49
|
# The given block will be called when the Request URI is recognized
|
41
50
|
# within the Request-Line.
|
42
51
|
#
|
43
|
-
# @yieldparam [
|
52
|
+
# @yieldparam [HttpParser::Instance] instance
|
44
53
|
# The state so far of the request / response being processed.
|
45
54
|
#
|
46
55
|
# @yieldparam [String] url
|
@@ -60,7 +69,7 @@ module HttpParser
|
|
60
69
|
# @yield [instance]
|
61
70
|
# The given block will be called when the status is recognized.
|
62
71
|
#
|
63
|
-
# @yieldparam [
|
72
|
+
# @yieldparam [HttpParser::Instance] instance
|
64
73
|
# The state so far of the request / response being processed.
|
65
74
|
#
|
66
75
|
def on_status_complete(&block)
|
@@ -76,7 +85,7 @@ module HttpParser
|
|
76
85
|
# The given block will be called when a Header name is recognized
|
77
86
|
# in the Headers.
|
78
87
|
#
|
79
|
-
# @yieldparam [
|
88
|
+
# @yieldparam [HttpParser::Instance] instance
|
80
89
|
# The state so far of the request / response being processed.
|
81
90
|
#
|
82
91
|
# @yieldparam [String] field
|
@@ -97,7 +106,7 @@ module HttpParser
|
|
97
106
|
# The given block will be called when a Header value is recognized
|
98
107
|
# in the Headers.
|
99
108
|
#
|
100
|
-
# @yieldparam [
|
109
|
+
# @yieldparam [HttpParser::Instance] instance
|
101
110
|
# The state so far of the request / response being processed.
|
102
111
|
#
|
103
112
|
# @yieldparam [String] value
|
@@ -117,7 +126,7 @@ module HttpParser
|
|
117
126
|
# @yield [instance]
|
118
127
|
# The given block will be called when the Headers stop.
|
119
128
|
#
|
120
|
-
# @yieldparam [
|
129
|
+
# @yieldparam [HttpParser::Instance] instance
|
121
130
|
# The state so far of the request / response being processed.
|
122
131
|
#
|
123
132
|
def on_headers_complete(&block)
|
@@ -133,7 +142,7 @@ module HttpParser
|
|
133
142
|
# The given block will be called when the body is recognized in the
|
134
143
|
# message body.
|
135
144
|
#
|
136
|
-
# @yieldparam [
|
145
|
+
# @yieldparam [HttpParser::Instance] instance
|
137
146
|
# The state so far of the request / response being processed.
|
138
147
|
#
|
139
148
|
# @yieldparam [String] body
|
@@ -154,7 +163,7 @@ module HttpParser
|
|
154
163
|
# @yield [instance]
|
155
164
|
# The given block will be called when the message completes.
|
156
165
|
#
|
157
|
-
# @yieldparam [
|
166
|
+
# @yieldparam [HttpParser::Instance] instance
|
158
167
|
# The state so far of the request / response being processed.
|
159
168
|
#
|
160
169
|
def on_message_complete(&block)
|
@@ -166,7 +175,7 @@ module HttpParser
|
|
166
175
|
#
|
167
176
|
# Parses data.
|
168
177
|
#
|
169
|
-
# @param [
|
178
|
+
# @param [HttpParser::Instance] inst
|
170
179
|
# The state so far of the request / response being processed.
|
171
180
|
#
|
172
181
|
# @param [String] data
|
data/lib/http-parser/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -284,5 +284,30 @@ describe HttpParser::Parser, "#initialize" do
|
|
284
284
|
@begun.should == 2
|
285
285
|
end
|
286
286
|
end
|
287
|
+
|
288
|
+
describe "method based instead of block based" do
|
289
|
+
class SomeParserClass
|
290
|
+
attr_reader :url
|
291
|
+
|
292
|
+
def on_url(inst, data)
|
293
|
+
@url = data
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
let(:expected) { '/foo?q=1' }
|
298
|
+
|
299
|
+
it "should simplify the process" do
|
300
|
+
callbacks = SomeParserClass.new
|
301
|
+
parser = described_class.new(callbacks)
|
302
|
+
|
303
|
+
parser.parse @inst, "GET "
|
304
|
+
|
305
|
+
callbacks.url.should be_nil
|
306
|
+
|
307
|
+
parser.parse @inst, "#{expected} HTTP/1.1"
|
308
|
+
|
309
|
+
callbacks.url.should == expected
|
310
|
+
end
|
311
|
+
end
|
287
312
|
end
|
288
313
|
|
metadata
CHANGED
@@ -1,79 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen von Takach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi-compiler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
20
22
|
version_requirements: !ruby/object:Gem::Requirement
|
21
23
|
requirements:
|
22
|
-
- -
|
24
|
+
- - ">="
|
23
25
|
- !ruby/object:Gem::Version
|
24
26
|
version: 0.0.2
|
25
|
-
type: :runtime
|
26
|
-
prerelease: false
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
35
36
|
version_requirements: !ruby/object:Gem::Requirement
|
36
37
|
requirements:
|
37
|
-
- -
|
38
|
+
- - ">="
|
38
39
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
MA==
|
41
|
-
type: :runtime
|
42
|
-
prerelease: false
|
40
|
+
version: '0'
|
43
41
|
- !ruby/object:Gem::Dependency
|
44
42
|
name: rspec
|
45
43
|
requirement: !ruby/object:Gem::Requirement
|
46
44
|
requirements:
|
47
|
-
- -
|
45
|
+
- - ">="
|
48
46
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
|
-
- -
|
52
|
+
- - ">="
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
56
|
-
MA==
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
54
|
+
version: '0'
|
59
55
|
- !ruby/object:Gem::Dependency
|
60
56
|
name: yard
|
61
57
|
requirement: !ruby/object:Gem::Requirement
|
62
58
|
requirements:
|
63
|
-
- -
|
59
|
+
- - ">="
|
64
60
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
66
|
-
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
|
-
- -
|
66
|
+
- - ">="
|
70
67
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
description: ! " A super fast http parser for ruby.\n Cross platform and multiple
|
76
|
-
ruby implementation support thanks to ffi.\n"
|
68
|
+
version: '0'
|
69
|
+
description: |2
|
70
|
+
A super fast http parser for ruby.
|
71
|
+
Cross platform and multiple ruby implementation support thanks to ffi.
|
77
72
|
email:
|
78
73
|
- steve@cotag.me
|
79
74
|
executables: []
|
@@ -82,12 +77,12 @@ extensions:
|
|
82
77
|
extra_rdoc_files:
|
83
78
|
- README.md
|
84
79
|
files:
|
85
|
-
- lib/http-parser.rb
|
86
80
|
- lib/http-parser/errors.rb
|
87
81
|
- lib/http-parser/ext.rb
|
88
82
|
- lib/http-parser/parser.rb
|
89
83
|
- lib/http-parser/types.rb
|
90
84
|
- lib/http-parser/version.rb
|
85
|
+
- lib/http-parser.rb
|
91
86
|
- Rakefile
|
92
87
|
- http-parser.gemspec
|
93
88
|
- README.md
|
@@ -108,19 +103,17 @@ require_paths:
|
|
108
103
|
- lib
|
109
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
105
|
requirements:
|
111
|
-
- -
|
106
|
+
- - ">="
|
112
107
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
114
|
-
MA==
|
108
|
+
version: '0'
|
115
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
110
|
requirements:
|
117
|
-
- -
|
111
|
+
- - ">="
|
118
112
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
120
|
-
MA==
|
113
|
+
version: '0'
|
121
114
|
requirements: []
|
122
115
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.0.
|
116
|
+
rubygems_version: 2.0.3
|
124
117
|
signing_key:
|
125
118
|
specification_version: 4
|
126
119
|
summary: Ruby bindings to joyent/http-parser
|