em-http-request 0.2.14 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of em-http-request might be problematic. Click here for more details.
- data/Changelog.md +5 -0
- data/Gemfile +15 -0
- data/Rakefile +6 -7
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/em-http-request.gemspec +3 -2
- data/ext/http11_client/http11_parser.c +418 -418
- data/ext/http11_client/http11_parser.rl +170 -170
- data/lib/em-http/client.rb +20 -4
- data/lib/em-http/multi.rb +55 -55
- data/lib/em-http/request.rb +1 -1
- data/spec/helper.rb +2 -2
- data/spec/mock_spec.rb +15 -11
- data/spec/request_spec.rb +20 -0
- data/spec/stub_server.rb +22 -22
- metadata +4 -3
- data/spec/spec.opts +0 -7
data/Changelog.md
CHANGED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source :gemcutter
|
2
|
+
|
3
|
+
gem 'eventmachine', '~> 0.12.9'
|
4
|
+
gem 'addressable', '~> 2.0.0'
|
5
|
+
gem 'rack'
|
6
|
+
|
7
|
+
gem 'mongrel', '~> 1.2.0.pre2', :require => ['mongrel', 'http11']
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'autotest'
|
11
|
+
gem 'ruby-debug19', :require => 'ruby-debug'
|
12
|
+
gem 'jeweler'
|
13
|
+
gem 'rspec', '~> 2.0.0'
|
14
|
+
gem 'em-websocket'
|
15
|
+
end
|
data/Rakefile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
Bundler.require :default, :development
|
4
|
+
|
1
5
|
require 'rake'
|
2
6
|
require 'rake/clean'
|
3
7
|
require 'rake/rdoctask'
|
@@ -34,13 +38,8 @@ task :ragel do
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
|
-
require '
|
38
|
-
|
39
|
-
Spec::Rake::SpecTask.new(:spec) do |t|
|
40
|
-
t.spec_opts ||= []
|
41
|
-
t.spec_opts << "--options" << "spec/spec.opts"
|
42
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
43
|
-
end
|
41
|
+
require 'rspec/core/rake_task'
|
42
|
+
Rspec::Core::RakeTask.new(:spec)
|
44
43
|
|
45
44
|
def make(makedir)
|
46
45
|
Dir.chdir(makedir) { sh MAKE }
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.15
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { 'rspec2' }
|
data/em-http-request.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{em-http-request}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.15"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ilya Grigorik"]
|
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.files = [
|
21
21
|
".gitignore",
|
22
22
|
"Changelog.md",
|
23
|
+
"Gemfile",
|
23
24
|
"LICENSE",
|
24
25
|
"README.md",
|
25
26
|
"Rakefile",
|
26
27
|
"VERSION",
|
28
|
+
"autotest/discover.rb",
|
27
29
|
"em-http-request.gemspec",
|
28
30
|
"examples/fetch.rb",
|
29
31
|
"examples/fibered-http.rb",
|
@@ -54,7 +56,6 @@ Gem::Specification.new do |s|
|
|
54
56
|
"spec/mock_spec.rb",
|
55
57
|
"spec/multi_spec.rb",
|
56
58
|
"spec/request_spec.rb",
|
57
|
-
"spec/spec.opts",
|
58
59
|
"spec/stallion.rb",
|
59
60
|
"spec/stub_server.rb"
|
60
61
|
]
|
@@ -1,418 +1,418 @@
|
|
1
|
-
|
2
|
-
#line 1 "http11_parser.rl"
|
3
|
-
/**
|
4
|
-
* Copyright (c) 2005 Zed A. Shaw
|
5
|
-
* You can redistribute it and/or modify it under the same terms as Ruby.
|
6
|
-
*/
|
7
|
-
|
8
|
-
#include "http11_parser.h"
|
9
|
-
#include <stdio.h>
|
10
|
-
#include <assert.h>
|
11
|
-
#include <stdlib.h>
|
12
|
-
#include <ctype.h>
|
13
|
-
#include <string.h>
|
14
|
-
|
15
|
-
#define LEN(AT, FPC) (FPC - buffer - parser->AT)
|
16
|
-
#define MARK(M,FPC) (parser->M = (FPC) - buffer)
|
17
|
-
#define PTR_TO(F) (buffer + parser->F)
|
18
|
-
#define L(M) fprintf(stderr, "" # M "\n");
|
19
|
-
|
20
|
-
|
21
|
-
/** machine **/
|
22
|
-
|
23
|
-
#line 95 "http11_parser.rl"
|
24
|
-
|
25
|
-
|
26
|
-
/** Data **/
|
27
|
-
|
28
|
-
#line 29 "http11_parser.c"
|
29
|
-
static const char _httpclient_parser_actions[] = {
|
30
|
-
0, 1, 0, 1, 1, 1, 2, 1,
|
31
|
-
3, 1, 4, 1, 5, 1, 7, 1,
|
32
|
-
8, 1, 10, 2, 0, 5, 2, 2,
|
33
|
-
3, 2, 3, 4, 2, 4, 10, 2,
|
34
|
-
6, 0, 2, 8, 10, 2, 9, 10,
|
35
|
-
2, 10, 9, 3, 2, 3, 4, 3,
|
36
|
-
4, 9, 10, 3, 4, 10, 9, 3,
|
37
|
-
6, 0, 5, 3, 8, 10, 9, 4,
|
38
|
-
2, 3, 4, 10, 5, 2, 3, 4,
|
39
|
-
9, 10, 5, 2, 3, 4, 10, 9
|
40
|
-
|
41
|
-
};
|
42
|
-
|
43
|
-
static const short _httpclient_parser_key_offsets[] = {
|
44
|
-
0, 0, 11, 12, 24, 29, 30, 31,
|
45
|
-
43, 58, 80, 95, 116, 131, 153, 168,
|
46
|
-
189, 204, 223, 238, 256, 257, 258, 259,
|
47
|
-
260, 262, 265, 267, 270, 272, 274, 276,
|
48
|
-
279, 281, 298, 314, 317, 319, 320, 322
|
49
|
-
};
|
50
|
-
|
51
|
-
static const char _httpclient_parser_trans_keys[] = {
|
52
|
-
10, 13, 48, 59, 72, 49, 57, 65,
|
53
|
-
70, 97, 102, 10, 10, 13, 32, 59,
|
54
|
-
9, 12, 48, 57, 65, 70, 97, 102,
|
55
|
-
10, 13, 32, 9, 12, 10, 10, 10,
|
56
|
-
13, 32, 59, 9, 12, 48, 57, 65,
|
57
|
-
70, 97, 102, 33, 124, 126, 35, 39,
|
58
|
-
42, 43, 45, 46, 48, 57, 65, 90,
|
59
|
-
94, 122, 10, 13, 32, 33, 59, 61,
|
60
|
-
124, 126, 9, 12, 35, 39, 42, 43,
|
61
|
-
45, 46, 48, 57, 65, 90, 94, 122,
|
62
|
-
33, 124, 126, 35, 39, 42, 43, 45,
|
63
|
-
46, 48, 57, 65, 90, 94, 122, 10,
|
64
|
-
13, 32, 33, 59, 124, 126, 9, 12,
|
65
|
-
35, 39, 42, 43, 45, 46, 48, 57,
|
66
|
-
65, 90, 94, 122, 33, 124, 126, 35,
|
67
|
-
39, 42, 43, 45, 46, 48, 57, 65,
|
68
|
-
90, 94, 122, 10, 13, 32, 33, 59,
|
69
|
-
61, 124, 126, 9, 12, 35, 39, 42,
|
70
|
-
43, 45, 46, 48, 57, 65, 90, 94,
|
71
|
-
122, 33, 124, 126, 35, 39, 42, 43,
|
72
|
-
45, 46, 48, 57, 65, 90, 94, 122,
|
73
|
-
10, 13, 32, 33, 59, 124, 126, 9,
|
74
|
-
12, 35, 39, 42, 43, 45, 46, 48,
|
75
|
-
57, 65, 90, 94, 122, 33, 124, 126,
|
76
|
-
35, 39, 42, 43, 45, 46, 48, 57,
|
77
|
-
65, 90, 94, 122, 10, 13, 33, 59,
|
78
|
-
61, 124, 126, 35, 39, 42, 43, 45,
|
79
|
-
46, 48, 57, 65, 90, 94, 122, 33,
|
80
|
-
124, 126, 35, 39, 42, 43, 45, 46,
|
81
|
-
48, 57, 65, 90, 94, 122, 10, 13,
|
82
|
-
33, 59, 124, 126, 35, 39, 42, 43,
|
83
|
-
45, 46, 48, 57, 65, 90, 94, 122,
|
84
|
-
84, 84, 80, 47, 48, 57, 46, 48,
|
85
|
-
57, 48, 57, 32, 48, 57, 48, 57,
|
86
|
-
48, 57, 48, 57, 10, 13, 32, 10,
|
87
|
-
13, 10, 13, 33, 124, 126, 35, 39,
|
88
|
-
42, 43, 45, 46, 48, 57, 65, 90,
|
89
|
-
94, 122, 33, 58, 124, 126, 35, 39,
|
90
|
-
42, 43, 45, 46, 48, 57, 65, 90,
|
91
|
-
94, 122, 10, 13, 32, 10, 13, 10,
|
92
|
-
10, 13, 0
|
93
|
-
};
|
94
|
-
|
95
|
-
static const char _httpclient_parser_single_lengths[] = {
|
96
|
-
0, 5, 1, 4, 3, 1, 1, 4,
|
97
|
-
3, 8, 3, 7, 3, 8, 3, 7,
|
98
|
-
3, 7, 3, 6, 1, 1, 1, 1,
|
99
|
-
0, 1, 0, 1, 0, 0, 0, 3,
|
100
|
-
2, 5, 4, 3, 2, 1, 2, 0
|
101
|
-
};
|
102
|
-
|
103
|
-
static const char _httpclient_parser_range_lengths[] = {
|
104
|
-
0, 3, 0, 4, 1, 0, 0, 4,
|
105
|
-
6, 7, 6, 7, 6, 7, 6, 7,
|
106
|
-
6, 6, 6, 6, 0, 0, 0, 0,
|
107
|
-
1, 1, 1, 1, 1, 1, 1, 0,
|
108
|
-
0, 6, 6, 0, 0, 0, 0, 0
|
109
|
-
};
|
110
|
-
|
111
|
-
static const short _httpclient_parser_index_offsets[] = {
|
112
|
-
0, 0, 9, 11, 20, 25, 27, 29,
|
113
|
-
38, 48, 64, 74, 89, 99, 115, 125,
|
114
|
-
140, 150, 164, 174, 187, 189, 191, 193,
|
115
|
-
195, 197, 200, 202, 205, 207, 209, 211,
|
116
|
-
215, 218, 230, 241, 245, 248, 250, 253
|
117
|
-
};
|
118
|
-
|
119
|
-
static const char _httpclient_parser_indicies[] = {
|
120
|
-
0, 2, 3, 5, 6, 4, 4, 4,
|
121
|
-
1, 0, 1, 8, 9, 7, 11, 7,
|
122
|
-
10, 10, 10, 1, 13, 14, 12, 12,
|
123
|
-
1, 13, 1, 15, 1, 16, 17, 7,
|
124
|
-
18, 7, 10, 10, 10, 1, 19, 19,
|
125
|
-
19, 19, 19, 19, 19, 19, 19, 1,
|
126
|
-
21, 22, 20, 23, 24, 25, 23, 23,
|
127
|
-
20, 23, 23, 23, 23, 23, 23, 1,
|
128
|
-
26, 26, 26, 26, 26, 26, 26, 26,
|
129
|
-
26, 1, 28, 29, 27, 30, 31, 30,
|
130
|
-
30, 27, 30, 30, 30, 30, 30, 30,
|
131
|
-
1, 32, 32, 32, 32, 32, 32, 32,
|
132
|
-
32, 32, 1, 33, 34, 20, 35, 36,
|
133
|
-
37, 35, 35, 20, 35, 35, 35, 35,
|
134
|
-
35, 35, 1, 38, 38, 38, 38, 38,
|
135
|
-
38, 38, 38, 38, 1, 39, 40, 27,
|
136
|
-
41, 42, 41, 41, 27, 41, 41, 41,
|
137
|
-
41, 41, 41, 1, 43, 43, 43, 43,
|
138
|
-
43, 43, 43, 43, 43, 1, 44, 45,
|
139
|
-
46, 47, 48, 46, 46, 46, 46, 46,
|
140
|
-
46, 46, 46, 1, 49, 49, 49, 49,
|
141
|
-
49, 49, 49, 49, 49, 1, 50, 51,
|
142
|
-
52, 53, 52, 52, 52, 52, 52, 52,
|
143
|
-
52, 52, 1, 54, 1, 55, 1, 56,
|
144
|
-
1, 57, 1, 58, 1, 59, 58, 1,
|
145
|
-
60, 1, 61, 60, 1, 62, 1, 63,
|
146
|
-
1, 64, 1, 66, 67, 68, 65, 70,
|
147
|
-
71, 69, 13, 14, 72, 72, 72, 72,
|
148
|
-
72, 72, 72, 72, 72, 1, 73, 74,
|
149
|
-
73, 73, 73, 73, 73, 73, 73, 73,
|
150
|
-
1, 76, 77, 78, 75, 80, 81, 79,
|
151
|
-
82, 1, 84, 85, 83, 1, 0
|
152
|
-
};
|
153
|
-
|
154
|
-
static const char _httpclient_parser_trans_targs[] = {
|
155
|
-
39, 0, 2, 3, 7, 16, 20, 4,
|
156
|
-
39, 6, 7, 12, 4, 39, 5, 39,
|
157
|
-
39, 5, 8, 9, 4, 39, 5, 9,
|
158
|
-
8, 10, 11, 4, 39, 5, 11, 8,
|
159
|
-
13, 39, 6, 13, 12, 14, 15, 39,
|
160
|
-
6, 15, 12, 17, 39, 2, 17, 16,
|
161
|
-
18, 19, 39, 2, 19, 16, 21, 22,
|
162
|
-
23, 24, 25, 26, 27, 28, 29, 30,
|
163
|
-
31, 32, 33, 37, 38, 32, 33, 37,
|
164
|
-
34, 34, 35, 36, 33, 37, 35, 36,
|
165
|
-
33, 37, 33, 32, 33, 37
|
166
|
-
};
|
167
|
-
|
168
|
-
static const char _httpclient_parser_trans_actions[] = {
|
169
|
-
37, 0, 0, 1, 1, 0, 1, 15,
|
170
|
-
59, 15, 0, 15, 0, 17, 0, 40,
|
171
|
-
34, 15, 15, 3, 43, 63, 43, 0,
|
172
|
-
43, 22, 7, 9, 28, 9, 0, 9,
|
173
|
-
3, 74, 43, 0, 43, 22, 7, 51,
|
174
|
-
9, 0, 9, 3, 68, 43, 0, 43,
|
175
|
-
22, 7, 47, 9, 0, 9, 0, 0,
|
176
|
-
0, 0, 0, 0, 0, 13, 1, 0,
|
177
|
-
0, 31, 55, 55, 31, 0, 11, 11,
|
178
|
-
3, 0, 5, 7, 25, 25, 7, 0,
|
179
|
-
9, 9, 0, 1, 19, 19
|
180
|
-
};
|
181
|
-
|
182
|
-
static const int httpclient_parser_start = 1;
|
183
|
-
static const int httpclient_parser_first_final = 39;
|
184
|
-
static const int httpclient_parser_error = 0;
|
185
|
-
|
186
|
-
static const int httpclient_parser_en_main = 1;
|
187
|
-
|
188
|
-
|
189
|
-
#line 99 "http11_parser.rl"
|
190
|
-
|
191
|
-
int httpclient_parser_init(httpclient_parser *parser) {
|
192
|
-
int cs = 0;
|
193
|
-
|
194
|
-
#line 195 "http11_parser.c"
|
195
|
-
{
|
196
|
-
cs = httpclient_parser_start;
|
197
|
-
}
|
198
|
-
|
199
|
-
#line 103 "http11_parser.rl"
|
200
|
-
parser->cs = cs;
|
201
|
-
parser->body_start = 0;
|
202
|
-
parser->content_len = 0;
|
203
|
-
parser->mark = 0;
|
204
|
-
parser->nread = 0;
|
205
|
-
parser->field_len = 0;
|
206
|
-
parser->field_start = 0;
|
207
|
-
|
208
|
-
return(1);
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
/** exec **/
|
213
|
-
size_t httpclient_parser_execute(httpclient_parser *parser, const char *buffer, size_t len, size_t off) {
|
214
|
-
const char *p, *pe;
|
215
|
-
int cs = parser->cs;
|
216
|
-
|
217
|
-
assert(off <= len && "offset past end of buffer");
|
218
|
-
|
219
|
-
p = buffer+off;
|
220
|
-
pe = buffer+len;
|
221
|
-
|
222
|
-
assert(*pe == '\0' && "pointer does not end on NUL");
|
223
|
-
assert(pe - p == len - off && "pointers aren't same distance");
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
#line 228 "http11_parser.c"
|
228
|
-
{
|
229
|
-
int _klen;
|
230
|
-
unsigned int _trans;
|
231
|
-
const char *_acts;
|
232
|
-
unsigned int _nacts;
|
233
|
-
const char *_keys;
|
234
|
-
|
235
|
-
if ( p == pe )
|
236
|
-
goto _test_eof;
|
237
|
-
if ( cs == 0 )
|
238
|
-
goto _out;
|
239
|
-
_resume:
|
240
|
-
_keys = _httpclient_parser_trans_keys + _httpclient_parser_key_offsets[cs];
|
241
|
-
_trans = _httpclient_parser_index_offsets[cs];
|
242
|
-
|
243
|
-
_klen = _httpclient_parser_single_lengths[cs];
|
244
|
-
if ( _klen > 0 ) {
|
245
|
-
const char *_lower = _keys;
|
246
|
-
const char *_mid;
|
247
|
-
const char *_upper = _keys + _klen - 1;
|
248
|
-
while (1) {
|
249
|
-
if ( _upper < _lower )
|
250
|
-
break;
|
251
|
-
|
252
|
-
_mid = _lower + ((_upper-_lower) >> 1);
|
253
|
-
if ( (*p) < *_mid )
|
254
|
-
_upper = _mid - 1;
|
255
|
-
else if ( (*p) > *_mid )
|
256
|
-
_lower = _mid + 1;
|
257
|
-
else {
|
258
|
-
_trans += (_mid - _keys);
|
259
|
-
goto _match;
|
260
|
-
}
|
261
|
-
}
|
262
|
-
_keys += _klen;
|
263
|
-
_trans += _klen;
|
264
|
-
}
|
265
|
-
|
266
|
-
_klen = _httpclient_parser_range_lengths[cs];
|
267
|
-
if ( _klen > 0 ) {
|
268
|
-
const char *_lower = _keys;
|
269
|
-
const char *_mid;
|
270
|
-
const char *_upper = _keys + (_klen<<1) - 2;
|
271
|
-
while (1) {
|
272
|
-
if ( _upper < _lower )
|
273
|
-
break;
|
274
|
-
|
275
|
-
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
276
|
-
if ( (*p) < _mid[0] )
|
277
|
-
_upper = _mid - 2;
|
278
|
-
else if ( (*p) > _mid[1] )
|
279
|
-
_lower = _mid + 2;
|
280
|
-
else {
|
281
|
-
_trans += ((_mid - _keys)>>1);
|
282
|
-
goto _match;
|
283
|
-
}
|
284
|
-
}
|
285
|
-
_trans += _klen;
|
286
|
-
}
|
287
|
-
|
288
|
-
_match:
|
289
|
-
_trans = _httpclient_parser_indicies[_trans];
|
290
|
-
cs = _httpclient_parser_trans_targs[_trans];
|
291
|
-
|
292
|
-
if ( _httpclient_parser_trans_actions[_trans] == 0 )
|
293
|
-
goto _again;
|
294
|
-
|
295
|
-
_acts = _httpclient_parser_actions + _httpclient_parser_trans_actions[_trans];
|
296
|
-
_nacts = (unsigned int) *_acts++;
|
297
|
-
while ( _nacts-- > 0 )
|
298
|
-
{
|
299
|
-
switch ( *_acts++ )
|
300
|
-
{
|
301
|
-
case 0:
|
302
|
-
#line 23 "http11_parser.rl"
|
303
|
-
{MARK(mark, p); }
|
304
|
-
break;
|
305
|
-
case 1:
|
306
|
-
#line 25 "http11_parser.rl"
|
307
|
-
{ MARK(field_start, p); }
|
308
|
-
break;
|
309
|
-
case 2:
|
310
|
-
#line 27 "http11_parser.rl"
|
311
|
-
{
|
312
|
-
parser->field_len = LEN(field_start, p);
|
313
|
-
}
|
314
|
-
break;
|
315
|
-
case 3:
|
316
|
-
#line 31 "http11_parser.rl"
|
317
|
-
{ MARK(mark, p); }
|
318
|
-
break;
|
319
|
-
case 4:
|
320
|
-
#line 33 "http11_parser.rl"
|
321
|
-
{
|
322
|
-
parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
|
323
|
-
}
|
324
|
-
break;
|
325
|
-
case 5:
|
326
|
-
#line 37 "http11_parser.rl"
|
327
|
-
{
|
328
|
-
parser->reason_phrase(parser->data, PTR_TO(mark), LEN(mark, p));
|
329
|
-
}
|
330
|
-
break;
|
331
|
-
case 6:
|
332
|
-
#line 41 "http11_parser.rl"
|
333
|
-
{
|
334
|
-
parser->status_code(parser->data, PTR_TO(mark), LEN(mark, p));
|
335
|
-
}
|
336
|
-
break;
|
337
|
-
case 7:
|
338
|
-
#line 45 "http11_parser.rl"
|
339
|
-
{
|
340
|
-
parser->http_version(parser->data, PTR_TO(mark), LEN(mark, p));
|
341
|
-
}
|
342
|
-
break;
|
343
|
-
case 8:
|
344
|
-
#line 49 "http11_parser.rl"
|
345
|
-
{
|
346
|
-
parser->chunk_size(parser->data, PTR_TO(mark), LEN(mark, p));
|
347
|
-
}
|
348
|
-
break;
|
349
|
-
case 9:
|
350
|
-
#line 53 "http11_parser.rl"
|
351
|
-
{
|
352
|
-
parser->last_chunk(parser->data, NULL, 0);
|
353
|
-
}
|
354
|
-
break;
|
355
|
-
case 10:
|
356
|
-
#line 57 "http11_parser.rl"
|
357
|
-
{
|
358
|
-
parser->body_start = p - buffer + 1;
|
359
|
-
if(parser->header_done != NULL)
|
360
|
-
parser->header_done(parser->data, p + 1, pe - p - 1);
|
361
|
-
{p++; goto _out; }
|
362
|
-
}
|
363
|
-
break;
|
364
|
-
#line 365 "http11_parser.c"
|
365
|
-
}
|
366
|
-
}
|
367
|
-
|
368
|
-
_again:
|
369
|
-
if ( cs == 0 )
|
370
|
-
goto _out;
|
371
|
-
if ( ++p != pe )
|
372
|
-
goto _resume;
|
373
|
-
_test_eof: {}
|
374
|
-
_out: {}
|
375
|
-
}
|
376
|
-
|
377
|
-
#line 130 "http11_parser.rl"
|
378
|
-
|
379
|
-
parser->cs = cs;
|
380
|
-
parser->nread += p - (buffer + off);
|
381
|
-
|
382
|
-
assert(p <= pe && "buffer overflow after parsing execute");
|
383
|
-
assert(parser->nread <= len && "nread longer than length");
|
384
|
-
assert(parser->body_start <= len && "body starts after buffer end");
|
385
|
-
assert(parser->mark < len && "mark is after buffer end");
|
386
|
-
assert(parser->field_len <= len && "field has length longer than whole buffer");
|
387
|
-
assert(parser->field_start < len && "field starts after buffer end");
|
388
|
-
|
389
|
-
if(parser->body_start) {
|
390
|
-
/* final \r\n combo encountered so stop right here */
|
391
|
-
parser->nread = parser->body_start;
|
392
|
-
}
|
393
|
-
|
394
|
-
return(parser->nread);
|
395
|
-
}
|
396
|
-
|
397
|
-
int httpclient_parser_finish(httpclient_parser *parser)
|
398
|
-
{
|
399
|
-
int cs = parser->cs;
|
400
|
-
|
401
|
-
parser->cs = cs;
|
402
|
-
|
403
|
-
if (httpclient_parser_has_error(parser) ) {
|
404
|
-
return -1;
|
405
|
-
} else if (httpclient_parser_is_finished(parser) ) {
|
406
|
-
return 1;
|
407
|
-
} else {
|
408
|
-
return 0;
|
409
|
-
}
|
410
|
-
}
|
411
|
-
|
412
|
-
int httpclient_parser_has_error(httpclient_parser *parser) {
|
413
|
-
return parser->cs == httpclient_parser_error;
|
414
|
-
}
|
415
|
-
|
416
|
-
int httpclient_parser_is_finished(httpclient_parser *parser) {
|
417
|
-
return parser->cs == httpclient_parser_first_final;
|
418
|
-
}
|
1
|
+
|
2
|
+
#line 1 "http11_parser.rl"
|
3
|
+
/**
|
4
|
+
* Copyright (c) 2005 Zed A. Shaw
|
5
|
+
* You can redistribute it and/or modify it under the same terms as Ruby.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "http11_parser.h"
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <assert.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <ctype.h>
|
13
|
+
#include <string.h>
|
14
|
+
|
15
|
+
#define LEN(AT, FPC) (FPC - buffer - parser->AT)
|
16
|
+
#define MARK(M,FPC) (parser->M = (FPC) - buffer)
|
17
|
+
#define PTR_TO(F) (buffer + parser->F)
|
18
|
+
#define L(M) fprintf(stderr, "" # M "\n");
|
19
|
+
|
20
|
+
|
21
|
+
/** machine **/
|
22
|
+
|
23
|
+
#line 95 "http11_parser.rl"
|
24
|
+
|
25
|
+
|
26
|
+
/** Data **/
|
27
|
+
|
28
|
+
#line 29 "http11_parser.c"
|
29
|
+
static const char _httpclient_parser_actions[] = {
|
30
|
+
0, 1, 0, 1, 1, 1, 2, 1,
|
31
|
+
3, 1, 4, 1, 5, 1, 7, 1,
|
32
|
+
8, 1, 10, 2, 0, 5, 2, 2,
|
33
|
+
3, 2, 3, 4, 2, 4, 10, 2,
|
34
|
+
6, 0, 2, 8, 10, 2, 9, 10,
|
35
|
+
2, 10, 9, 3, 2, 3, 4, 3,
|
36
|
+
4, 9, 10, 3, 4, 10, 9, 3,
|
37
|
+
6, 0, 5, 3, 8, 10, 9, 4,
|
38
|
+
2, 3, 4, 10, 5, 2, 3, 4,
|
39
|
+
9, 10, 5, 2, 3, 4, 10, 9
|
40
|
+
|
41
|
+
};
|
42
|
+
|
43
|
+
static const short _httpclient_parser_key_offsets[] = {
|
44
|
+
0, 0, 11, 12, 24, 29, 30, 31,
|
45
|
+
43, 58, 80, 95, 116, 131, 153, 168,
|
46
|
+
189, 204, 223, 238, 256, 257, 258, 259,
|
47
|
+
260, 262, 265, 267, 270, 272, 274, 276,
|
48
|
+
279, 281, 298, 314, 317, 319, 320, 322
|
49
|
+
};
|
50
|
+
|
51
|
+
static const char _httpclient_parser_trans_keys[] = {
|
52
|
+
10, 13, 48, 59, 72, 49, 57, 65,
|
53
|
+
70, 97, 102, 10, 10, 13, 32, 59,
|
54
|
+
9, 12, 48, 57, 65, 70, 97, 102,
|
55
|
+
10, 13, 32, 9, 12, 10, 10, 10,
|
56
|
+
13, 32, 59, 9, 12, 48, 57, 65,
|
57
|
+
70, 97, 102, 33, 124, 126, 35, 39,
|
58
|
+
42, 43, 45, 46, 48, 57, 65, 90,
|
59
|
+
94, 122, 10, 13, 32, 33, 59, 61,
|
60
|
+
124, 126, 9, 12, 35, 39, 42, 43,
|
61
|
+
45, 46, 48, 57, 65, 90, 94, 122,
|
62
|
+
33, 124, 126, 35, 39, 42, 43, 45,
|
63
|
+
46, 48, 57, 65, 90, 94, 122, 10,
|
64
|
+
13, 32, 33, 59, 124, 126, 9, 12,
|
65
|
+
35, 39, 42, 43, 45, 46, 48, 57,
|
66
|
+
65, 90, 94, 122, 33, 124, 126, 35,
|
67
|
+
39, 42, 43, 45, 46, 48, 57, 65,
|
68
|
+
90, 94, 122, 10, 13, 32, 33, 59,
|
69
|
+
61, 124, 126, 9, 12, 35, 39, 42,
|
70
|
+
43, 45, 46, 48, 57, 65, 90, 94,
|
71
|
+
122, 33, 124, 126, 35, 39, 42, 43,
|
72
|
+
45, 46, 48, 57, 65, 90, 94, 122,
|
73
|
+
10, 13, 32, 33, 59, 124, 126, 9,
|
74
|
+
12, 35, 39, 42, 43, 45, 46, 48,
|
75
|
+
57, 65, 90, 94, 122, 33, 124, 126,
|
76
|
+
35, 39, 42, 43, 45, 46, 48, 57,
|
77
|
+
65, 90, 94, 122, 10, 13, 33, 59,
|
78
|
+
61, 124, 126, 35, 39, 42, 43, 45,
|
79
|
+
46, 48, 57, 65, 90, 94, 122, 33,
|
80
|
+
124, 126, 35, 39, 42, 43, 45, 46,
|
81
|
+
48, 57, 65, 90, 94, 122, 10, 13,
|
82
|
+
33, 59, 124, 126, 35, 39, 42, 43,
|
83
|
+
45, 46, 48, 57, 65, 90, 94, 122,
|
84
|
+
84, 84, 80, 47, 48, 57, 46, 48,
|
85
|
+
57, 48, 57, 32, 48, 57, 48, 57,
|
86
|
+
48, 57, 48, 57, 10, 13, 32, 10,
|
87
|
+
13, 10, 13, 33, 124, 126, 35, 39,
|
88
|
+
42, 43, 45, 46, 48, 57, 65, 90,
|
89
|
+
94, 122, 33, 58, 124, 126, 35, 39,
|
90
|
+
42, 43, 45, 46, 48, 57, 65, 90,
|
91
|
+
94, 122, 10, 13, 32, 10, 13, 10,
|
92
|
+
10, 13, 0
|
93
|
+
};
|
94
|
+
|
95
|
+
static const char _httpclient_parser_single_lengths[] = {
|
96
|
+
0, 5, 1, 4, 3, 1, 1, 4,
|
97
|
+
3, 8, 3, 7, 3, 8, 3, 7,
|
98
|
+
3, 7, 3, 6, 1, 1, 1, 1,
|
99
|
+
0, 1, 0, 1, 0, 0, 0, 3,
|
100
|
+
2, 5, 4, 3, 2, 1, 2, 0
|
101
|
+
};
|
102
|
+
|
103
|
+
static const char _httpclient_parser_range_lengths[] = {
|
104
|
+
0, 3, 0, 4, 1, 0, 0, 4,
|
105
|
+
6, 7, 6, 7, 6, 7, 6, 7,
|
106
|
+
6, 6, 6, 6, 0, 0, 0, 0,
|
107
|
+
1, 1, 1, 1, 1, 1, 1, 0,
|
108
|
+
0, 6, 6, 0, 0, 0, 0, 0
|
109
|
+
};
|
110
|
+
|
111
|
+
static const short _httpclient_parser_index_offsets[] = {
|
112
|
+
0, 0, 9, 11, 20, 25, 27, 29,
|
113
|
+
38, 48, 64, 74, 89, 99, 115, 125,
|
114
|
+
140, 150, 164, 174, 187, 189, 191, 193,
|
115
|
+
195, 197, 200, 202, 205, 207, 209, 211,
|
116
|
+
215, 218, 230, 241, 245, 248, 250, 253
|
117
|
+
};
|
118
|
+
|
119
|
+
static const char _httpclient_parser_indicies[] = {
|
120
|
+
0, 2, 3, 5, 6, 4, 4, 4,
|
121
|
+
1, 0, 1, 8, 9, 7, 11, 7,
|
122
|
+
10, 10, 10, 1, 13, 14, 12, 12,
|
123
|
+
1, 13, 1, 15, 1, 16, 17, 7,
|
124
|
+
18, 7, 10, 10, 10, 1, 19, 19,
|
125
|
+
19, 19, 19, 19, 19, 19, 19, 1,
|
126
|
+
21, 22, 20, 23, 24, 25, 23, 23,
|
127
|
+
20, 23, 23, 23, 23, 23, 23, 1,
|
128
|
+
26, 26, 26, 26, 26, 26, 26, 26,
|
129
|
+
26, 1, 28, 29, 27, 30, 31, 30,
|
130
|
+
30, 27, 30, 30, 30, 30, 30, 30,
|
131
|
+
1, 32, 32, 32, 32, 32, 32, 32,
|
132
|
+
32, 32, 1, 33, 34, 20, 35, 36,
|
133
|
+
37, 35, 35, 20, 35, 35, 35, 35,
|
134
|
+
35, 35, 1, 38, 38, 38, 38, 38,
|
135
|
+
38, 38, 38, 38, 1, 39, 40, 27,
|
136
|
+
41, 42, 41, 41, 27, 41, 41, 41,
|
137
|
+
41, 41, 41, 1, 43, 43, 43, 43,
|
138
|
+
43, 43, 43, 43, 43, 1, 44, 45,
|
139
|
+
46, 47, 48, 46, 46, 46, 46, 46,
|
140
|
+
46, 46, 46, 1, 49, 49, 49, 49,
|
141
|
+
49, 49, 49, 49, 49, 1, 50, 51,
|
142
|
+
52, 53, 52, 52, 52, 52, 52, 52,
|
143
|
+
52, 52, 1, 54, 1, 55, 1, 56,
|
144
|
+
1, 57, 1, 58, 1, 59, 58, 1,
|
145
|
+
60, 1, 61, 60, 1, 62, 1, 63,
|
146
|
+
1, 64, 1, 66, 67, 68, 65, 70,
|
147
|
+
71, 69, 13, 14, 72, 72, 72, 72,
|
148
|
+
72, 72, 72, 72, 72, 1, 73, 74,
|
149
|
+
73, 73, 73, 73, 73, 73, 73, 73,
|
150
|
+
1, 76, 77, 78, 75, 80, 81, 79,
|
151
|
+
82, 1, 84, 85, 83, 1, 0
|
152
|
+
};
|
153
|
+
|
154
|
+
static const char _httpclient_parser_trans_targs[] = {
|
155
|
+
39, 0, 2, 3, 7, 16, 20, 4,
|
156
|
+
39, 6, 7, 12, 4, 39, 5, 39,
|
157
|
+
39, 5, 8, 9, 4, 39, 5, 9,
|
158
|
+
8, 10, 11, 4, 39, 5, 11, 8,
|
159
|
+
13, 39, 6, 13, 12, 14, 15, 39,
|
160
|
+
6, 15, 12, 17, 39, 2, 17, 16,
|
161
|
+
18, 19, 39, 2, 19, 16, 21, 22,
|
162
|
+
23, 24, 25, 26, 27, 28, 29, 30,
|
163
|
+
31, 32, 33, 37, 38, 32, 33, 37,
|
164
|
+
34, 34, 35, 36, 33, 37, 35, 36,
|
165
|
+
33, 37, 33, 32, 33, 37
|
166
|
+
};
|
167
|
+
|
168
|
+
static const char _httpclient_parser_trans_actions[] = {
|
169
|
+
37, 0, 0, 1, 1, 0, 1, 15,
|
170
|
+
59, 15, 0, 15, 0, 17, 0, 40,
|
171
|
+
34, 15, 15, 3, 43, 63, 43, 0,
|
172
|
+
43, 22, 7, 9, 28, 9, 0, 9,
|
173
|
+
3, 74, 43, 0, 43, 22, 7, 51,
|
174
|
+
9, 0, 9, 3, 68, 43, 0, 43,
|
175
|
+
22, 7, 47, 9, 0, 9, 0, 0,
|
176
|
+
0, 0, 0, 0, 0, 13, 1, 0,
|
177
|
+
0, 31, 55, 55, 31, 0, 11, 11,
|
178
|
+
3, 0, 5, 7, 25, 25, 7, 0,
|
179
|
+
9, 9, 0, 1, 19, 19
|
180
|
+
};
|
181
|
+
|
182
|
+
static const int httpclient_parser_start = 1;
|
183
|
+
static const int httpclient_parser_first_final = 39;
|
184
|
+
static const int httpclient_parser_error = 0;
|
185
|
+
|
186
|
+
static const int httpclient_parser_en_main = 1;
|
187
|
+
|
188
|
+
|
189
|
+
#line 99 "http11_parser.rl"
|
190
|
+
|
191
|
+
int httpclient_parser_init(httpclient_parser *parser) {
|
192
|
+
int cs = 0;
|
193
|
+
|
194
|
+
#line 195 "http11_parser.c"
|
195
|
+
{
|
196
|
+
cs = httpclient_parser_start;
|
197
|
+
}
|
198
|
+
|
199
|
+
#line 103 "http11_parser.rl"
|
200
|
+
parser->cs = cs;
|
201
|
+
parser->body_start = 0;
|
202
|
+
parser->content_len = 0;
|
203
|
+
parser->mark = 0;
|
204
|
+
parser->nread = 0;
|
205
|
+
parser->field_len = 0;
|
206
|
+
parser->field_start = 0;
|
207
|
+
|
208
|
+
return(1);
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
/** exec **/
|
213
|
+
size_t httpclient_parser_execute(httpclient_parser *parser, const char *buffer, size_t len, size_t off) {
|
214
|
+
const char *p, *pe;
|
215
|
+
int cs = parser->cs;
|
216
|
+
|
217
|
+
assert(off <= len && "offset past end of buffer");
|
218
|
+
|
219
|
+
p = buffer+off;
|
220
|
+
pe = buffer+len;
|
221
|
+
|
222
|
+
assert(*pe == '\0' && "pointer does not end on NUL");
|
223
|
+
assert(pe - p == len - off && "pointers aren't same distance");
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
#line 228 "http11_parser.c"
|
228
|
+
{
|
229
|
+
int _klen;
|
230
|
+
unsigned int _trans;
|
231
|
+
const char *_acts;
|
232
|
+
unsigned int _nacts;
|
233
|
+
const char *_keys;
|
234
|
+
|
235
|
+
if ( p == pe )
|
236
|
+
goto _test_eof;
|
237
|
+
if ( cs == 0 )
|
238
|
+
goto _out;
|
239
|
+
_resume:
|
240
|
+
_keys = _httpclient_parser_trans_keys + _httpclient_parser_key_offsets[cs];
|
241
|
+
_trans = _httpclient_parser_index_offsets[cs];
|
242
|
+
|
243
|
+
_klen = _httpclient_parser_single_lengths[cs];
|
244
|
+
if ( _klen > 0 ) {
|
245
|
+
const char *_lower = _keys;
|
246
|
+
const char *_mid;
|
247
|
+
const char *_upper = _keys + _klen - 1;
|
248
|
+
while (1) {
|
249
|
+
if ( _upper < _lower )
|
250
|
+
break;
|
251
|
+
|
252
|
+
_mid = _lower + ((_upper-_lower) >> 1);
|
253
|
+
if ( (*p) < *_mid )
|
254
|
+
_upper = _mid - 1;
|
255
|
+
else if ( (*p) > *_mid )
|
256
|
+
_lower = _mid + 1;
|
257
|
+
else {
|
258
|
+
_trans += (_mid - _keys);
|
259
|
+
goto _match;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
_keys += _klen;
|
263
|
+
_trans += _klen;
|
264
|
+
}
|
265
|
+
|
266
|
+
_klen = _httpclient_parser_range_lengths[cs];
|
267
|
+
if ( _klen > 0 ) {
|
268
|
+
const char *_lower = _keys;
|
269
|
+
const char *_mid;
|
270
|
+
const char *_upper = _keys + (_klen<<1) - 2;
|
271
|
+
while (1) {
|
272
|
+
if ( _upper < _lower )
|
273
|
+
break;
|
274
|
+
|
275
|
+
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
276
|
+
if ( (*p) < _mid[0] )
|
277
|
+
_upper = _mid - 2;
|
278
|
+
else if ( (*p) > _mid[1] )
|
279
|
+
_lower = _mid + 2;
|
280
|
+
else {
|
281
|
+
_trans += ((_mid - _keys)>>1);
|
282
|
+
goto _match;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
_trans += _klen;
|
286
|
+
}
|
287
|
+
|
288
|
+
_match:
|
289
|
+
_trans = _httpclient_parser_indicies[_trans];
|
290
|
+
cs = _httpclient_parser_trans_targs[_trans];
|
291
|
+
|
292
|
+
if ( _httpclient_parser_trans_actions[_trans] == 0 )
|
293
|
+
goto _again;
|
294
|
+
|
295
|
+
_acts = _httpclient_parser_actions + _httpclient_parser_trans_actions[_trans];
|
296
|
+
_nacts = (unsigned int) *_acts++;
|
297
|
+
while ( _nacts-- > 0 )
|
298
|
+
{
|
299
|
+
switch ( *_acts++ )
|
300
|
+
{
|
301
|
+
case 0:
|
302
|
+
#line 23 "http11_parser.rl"
|
303
|
+
{MARK(mark, p); }
|
304
|
+
break;
|
305
|
+
case 1:
|
306
|
+
#line 25 "http11_parser.rl"
|
307
|
+
{ MARK(field_start, p); }
|
308
|
+
break;
|
309
|
+
case 2:
|
310
|
+
#line 27 "http11_parser.rl"
|
311
|
+
{
|
312
|
+
parser->field_len = LEN(field_start, p);
|
313
|
+
}
|
314
|
+
break;
|
315
|
+
case 3:
|
316
|
+
#line 31 "http11_parser.rl"
|
317
|
+
{ MARK(mark, p); }
|
318
|
+
break;
|
319
|
+
case 4:
|
320
|
+
#line 33 "http11_parser.rl"
|
321
|
+
{
|
322
|
+
parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
|
323
|
+
}
|
324
|
+
break;
|
325
|
+
case 5:
|
326
|
+
#line 37 "http11_parser.rl"
|
327
|
+
{
|
328
|
+
parser->reason_phrase(parser->data, PTR_TO(mark), LEN(mark, p));
|
329
|
+
}
|
330
|
+
break;
|
331
|
+
case 6:
|
332
|
+
#line 41 "http11_parser.rl"
|
333
|
+
{
|
334
|
+
parser->status_code(parser->data, PTR_TO(mark), LEN(mark, p));
|
335
|
+
}
|
336
|
+
break;
|
337
|
+
case 7:
|
338
|
+
#line 45 "http11_parser.rl"
|
339
|
+
{
|
340
|
+
parser->http_version(parser->data, PTR_TO(mark), LEN(mark, p));
|
341
|
+
}
|
342
|
+
break;
|
343
|
+
case 8:
|
344
|
+
#line 49 "http11_parser.rl"
|
345
|
+
{
|
346
|
+
parser->chunk_size(parser->data, PTR_TO(mark), LEN(mark, p));
|
347
|
+
}
|
348
|
+
break;
|
349
|
+
case 9:
|
350
|
+
#line 53 "http11_parser.rl"
|
351
|
+
{
|
352
|
+
parser->last_chunk(parser->data, NULL, 0);
|
353
|
+
}
|
354
|
+
break;
|
355
|
+
case 10:
|
356
|
+
#line 57 "http11_parser.rl"
|
357
|
+
{
|
358
|
+
parser->body_start = p - buffer + 1;
|
359
|
+
if(parser->header_done != NULL)
|
360
|
+
parser->header_done(parser->data, p + 1, pe - p - 1);
|
361
|
+
{p++; goto _out; }
|
362
|
+
}
|
363
|
+
break;
|
364
|
+
#line 365 "http11_parser.c"
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
_again:
|
369
|
+
if ( cs == 0 )
|
370
|
+
goto _out;
|
371
|
+
if ( ++p != pe )
|
372
|
+
goto _resume;
|
373
|
+
_test_eof: {}
|
374
|
+
_out: {}
|
375
|
+
}
|
376
|
+
|
377
|
+
#line 130 "http11_parser.rl"
|
378
|
+
|
379
|
+
parser->cs = cs;
|
380
|
+
parser->nread += p - (buffer + off);
|
381
|
+
|
382
|
+
assert(p <= pe && "buffer overflow after parsing execute");
|
383
|
+
assert(parser->nread <= len && "nread longer than length");
|
384
|
+
assert(parser->body_start <= len && "body starts after buffer end");
|
385
|
+
assert(parser->mark < len && "mark is after buffer end");
|
386
|
+
assert(parser->field_len <= len && "field has length longer than whole buffer");
|
387
|
+
assert(parser->field_start < len && "field starts after buffer end");
|
388
|
+
|
389
|
+
if(parser->body_start) {
|
390
|
+
/* final \r\n combo encountered so stop right here */
|
391
|
+
parser->nread = parser->body_start;
|
392
|
+
}
|
393
|
+
|
394
|
+
return(parser->nread);
|
395
|
+
}
|
396
|
+
|
397
|
+
int httpclient_parser_finish(httpclient_parser *parser)
|
398
|
+
{
|
399
|
+
int cs = parser->cs;
|
400
|
+
|
401
|
+
parser->cs = cs;
|
402
|
+
|
403
|
+
if (httpclient_parser_has_error(parser) ) {
|
404
|
+
return -1;
|
405
|
+
} else if (httpclient_parser_is_finished(parser) ) {
|
406
|
+
return 1;
|
407
|
+
} else {
|
408
|
+
return 0;
|
409
|
+
}
|
410
|
+
}
|
411
|
+
|
412
|
+
int httpclient_parser_has_error(httpclient_parser *parser) {
|
413
|
+
return parser->cs == httpclient_parser_error;
|
414
|
+
}
|
415
|
+
|
416
|
+
int httpclient_parser_is_finished(httpclient_parser *parser) {
|
417
|
+
return parser->cs == httpclient_parser_first_final;
|
418
|
+
}
|