http_parser.rb 0.5.1-x86-mingw32 → 0.5.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile.lock +16 -16
  2. data/LICENSE-MIT +20 -0
  3. data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +68 -11
  4. data/ext/ruby_http_parser/ruby_http_parser.c +74 -6
  5. data/ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT +1 -1
  6. data/ext/ruby_http_parser/vendor/http-parser/http_parser.c +52 -10
  7. data/ext/ruby_http_parser/vendor/http-parser/http_parser.h +3 -1
  8. data/ext/ruby_http_parser/vendor/http-parser/test.c +89 -3
  9. data/ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT +26 -1
  10. data/ext/ruby_http_parser/vendor/http-parser-java/README.md +23 -143
  11. data/ext/ruby_http_parser/vendor/http-parser-java/TODO +3 -0
  12. data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +74 -0
  13. data/ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar +0 -0
  14. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +115 -61
  15. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +19 -3
  16. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +8 -0
  17. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +34 -0
  18. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +12 -0
  19. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +4 -2
  20. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +64 -52
  21. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +5 -0
  22. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +323 -0
  23. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/{lolevel/Util.java → Util.java} +27 -28
  24. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +259 -85
  25. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +1 -0
  26. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +324 -0
  27. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +69 -0
  28. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +51 -0
  29. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +15 -0
  30. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +47 -0
  31. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +183 -447
  32. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +61 -0
  33. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +2 -1
  34. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +26 -0
  35. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +165 -0
  36. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +58 -0
  37. data/ext/ruby_http_parser/vendor/http-parser-java/test.c +232 -29
  38. data/ext/ruby_http_parser/vendor/http-parser-java/test_permutations +1 -1
  39. data/ext/ruby_http_parser/vendor/http-parser-java/test_unit +1 -1
  40. data/ext/ruby_http_parser/vendor/http-parser-java/test_utf8 +1 -0
  41. data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +154 -7
  42. data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +17 -0
  43. data/http_parser.rb.gemspec +8 -2
  44. data/lib/1.8/ruby_http_parser.so +0 -0
  45. data/lib/1.9/ruby_http_parser.so +0 -0
  46. data/lib/http_parser.rb +17 -0
  47. data/spec/parser_spec.rb +97 -6
  48. data/tasks/compile.rake +3 -1
  49. metadata +83 -20
  50. data/ext/ruby_http_parser/vendor/http-parser-java/CONTRIBUTIONS +0 -4
@@ -1,5 +1,7 @@
1
1
  package http_parser;
2
2
 
3
+ import java.nio.ByteBuffer;
4
+
3
5
  public class HTTPParser extends http_parser.lolevel.HTTPParser {
4
6
 
5
7
  public HTTPParser() { super(); }
@@ -28,4 +30,7 @@ public class HTTPParser extends http_parser.lolevel.HTTPParser {
28
30
  public boolean shouldKeepAlive() {
29
31
  return super.http_should_keep_alive();
30
32
  }
33
+ public void execute(ParserSettings settings, ByteBuffer data) {
34
+ this.execute(settings.getLoLevelSettings(), data);
35
+ }
31
36
  }
@@ -0,0 +1,323 @@
1
+ package http_parser;
2
+
3
+
4
+
5
+ import primitive.collection.ByteList;
6
+
7
+ public class ParserSettings extends http_parser.lolevel.ParserSettings {
8
+
9
+ public HTTPCallback on_message_begin;
10
+ public HTTPDataCallback on_path;
11
+ public HTTPDataCallback on_query_string;
12
+ public HTTPDataCallback on_url;
13
+ public HTTPDataCallback on_fragment;
14
+ public HTTPDataCallback on_header_field;
15
+ public HTTPDataCallback on_header_value;
16
+
17
+ public HTTPCallback on_headers_complete;
18
+ public HTTPDataCallback on_body;
19
+ public HTTPCallback on_message_complete;
20
+
21
+ public HTTPErrorCallback on_error;
22
+
23
+ private HTTPCallback _on_message_begin;
24
+ private HTTPDataCallback _on_path;
25
+ private HTTPDataCallback _on_query_string;
26
+ private HTTPDataCallback _on_url;
27
+ private HTTPDataCallback _on_fragment;
28
+ private HTTPDataCallback _on_header_field;
29
+ private HTTPDataCallback _on_header_value;
30
+ private HTTPCallback _on_headers_complete;
31
+ private HTTPDataCallback _on_body;
32
+ private HTTPCallback _on_message_complete;
33
+ private HTTPErrorCallback _on_error;
34
+
35
+ private http_parser.lolevel.ParserSettings settings;
36
+
37
+ protected ByteList field = new ByteList();
38
+ protected ByteList value = new ByteList();
39
+ protected ByteList body = new ByteList();
40
+
41
+ public ParserSettings() {
42
+ this.settings = new http_parser.lolevel.ParserSettings();
43
+ createMirrorCallbacks();
44
+ attachCallbacks();
45
+ }
46
+
47
+ protected http_parser.lolevel.ParserSettings getLoLevelSettings() {
48
+ return this.settings;
49
+ }
50
+
51
+ private void createMirrorCallbacks() {
52
+ this._on_message_begin = new HTTPCallback() {
53
+ public int cb(HTTPParser p) {
54
+ if (null != ParserSettings.this.on_message_begin) {
55
+ return ParserSettings.this.on_message_begin.cb(p);
56
+ }
57
+ return 0;
58
+ }
59
+ };
60
+ this._on_path = new HTTPDataCallback() {
61
+ @Override
62
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
63
+ if (null != ParserSettings.this.on_path) {
64
+ return ParserSettings.this.on_path.cb(p, by, pos, len);
65
+ }
66
+ return 0;
67
+ }
68
+ };
69
+ this._on_query_string = new HTTPDataCallback() {
70
+ @Override
71
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
72
+ if (null != ParserSettings.this.on_query_string) {
73
+ return ParserSettings.this.on_query_string.cb(p, by, pos, len);
74
+ }
75
+ return 0;
76
+ }
77
+ };
78
+ this._on_url = new HTTPDataCallback() {
79
+ @Override
80
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
81
+ if (null != ParserSettings.this.on_url) {
82
+ return ParserSettings.this.on_url.cb(p, by, pos, len);
83
+ }
84
+ return 0;
85
+ }
86
+ };
87
+ this._on_fragment = new HTTPDataCallback() {
88
+ @Override
89
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
90
+ if (null != ParserSettings.this.on_fragment) {
91
+ return ParserSettings.this.on_fragment.cb(p, by, pos, len);
92
+ }
93
+ return 0;
94
+ }
95
+ };
96
+ this._on_error = new HTTPErrorCallback() {
97
+ @Override
98
+ public void cb(HTTPParser parser, String error) {
99
+ if (null != ParserSettings.this.on_error) {
100
+ ParserSettings.this.on_error.cb(parser, error);
101
+ } else {
102
+ throw new HTTPException(error);
103
+ }
104
+
105
+ }
106
+ };
107
+
108
+
109
+
110
+ // (on_header_field and on_header_value shortened to on_h_*)
111
+ // ------------------------ ------------ --------------------------------------------
112
+ // | State (prev. callback) | Callback | Description/action |
113
+ // ------------------------ ------------ --------------------------------------------
114
+ // | nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
115
+ // | | | into it |
116
+ // ------------------------ ------------ --------------------------------------------
117
+ // | value | on_h_field | New header started. |
118
+ // | | | Copy current name,value buffers to headers |
119
+ // | | | list and allocate new buffer for new name |
120
+ // ------------------------ ------------ --------------------------------------------
121
+ // | field | on_h_field | Previous name continues. Reallocate name |
122
+ // | | | buffer and append callback data to it |
123
+ // ------------------------ ------------ --------------------------------------------
124
+ // | field | on_h_value | Value for current header started. Allocate |
125
+ // | | | new buffer and copy callback data to it |
126
+ // ------------------------ ------------ --------------------------------------------
127
+ // | value | on_h_value | Value continues. Reallocate value buffer |
128
+ // | | | and append callback data to it |
129
+ // ------------------------ ------------ --------------------------------------------
130
+ this._on_header_field = new HTTPDataCallback() {
131
+ @Override
132
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
133
+ // previous value complete, call on_value with full value, reset value.
134
+ if (0 != ParserSettings.this.value.size()) {
135
+ // check we're even interested...
136
+ if (null != ParserSettings.this.on_header_value) {
137
+ byte [] valueArr = ParserSettings.this.value.toArray();
138
+ int ret = ParserSettings.this.on_header_value.cb(p, valueArr, 0, valueArr.length);
139
+ if (0 != ret) {
140
+ return ret;
141
+ }
142
+ ParserSettings.this.value.clear();
143
+ }
144
+ }
145
+
146
+ if (null == ParserSettings.this.on_header_field) {
147
+ return 0;
148
+ }
149
+
150
+ ParserSettings.this.field.addAll(by);
151
+ return 0;
152
+ }
153
+ };
154
+ this._on_header_value = new HTTPDataCallback() {
155
+ @Override
156
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
157
+
158
+ // previous field complete, call on_field with full field value, reset field.
159
+ if (0 != ParserSettings.this.field.size()) {
160
+ // check we're even interested...
161
+ if (null != ParserSettings.this.on_header_field) {
162
+ byte [] fieldArr = ParserSettings.this.field.toArray();
163
+ int ret = ParserSettings.this.on_header_field.cb(p, fieldArr, 0, fieldArr.length);
164
+ if (0 != ret) {
165
+ return ret;
166
+ }
167
+ ParserSettings.this.field.clear();
168
+ }
169
+ }
170
+
171
+ if (null == ParserSettings.this.on_header_value) {
172
+ return 0;
173
+ }
174
+ ParserSettings.this.value.addAll(by);
175
+ return 0;
176
+ }
177
+ };
178
+ this._on_headers_complete = new HTTPCallback() {
179
+ @Override
180
+ public int cb(HTTPParser parser) {
181
+ // is there an uncompleted value ... ?
182
+ if (0 != ParserSettings.this.value.size()) {
183
+ // check we're even interested...
184
+ if (null != ParserSettings.this.on_header_value) {
185
+ byte [] valueArr = ParserSettings.this.value.toArray();
186
+ int ret = ParserSettings.this.on_header_value.cb(parser, valueArr, 0, valueArr.length);
187
+ if (0 != ret) {
188
+ return ret;
189
+ }
190
+ ParserSettings.this.value.clear();
191
+ }
192
+ }
193
+ if (null != ParserSettings.this.on_headers_complete) {
194
+ return ParserSettings.this.on_headers_complete.cb(parser);
195
+ }
196
+ return 0;
197
+ }
198
+
199
+ };
200
+ this._on_body = new HTTPDataCallback() {
201
+ @Override
202
+ public int cb(HTTPParser p, byte[] by, int pos, int len) {
203
+ if (null != ParserSettings.this.on_body) {
204
+ ParserSettings.this.body.addAll(by, pos, len);
205
+ }
206
+ return 0;
207
+ }
208
+ };
209
+
210
+ this._on_message_complete = new HTTPCallback() {
211
+ @Override
212
+ public int cb(HTTPParser parser) {
213
+ if (null != ParserSettings.this.on_body) {
214
+ byte [] body = ParserSettings.this.body.toArray();
215
+ int ret = ParserSettings.this.on_body.cb(parser, body, 0, body.length);
216
+ if (0!=ret) {
217
+ return ret;
218
+ }
219
+ ParserSettings.this.body.clear();
220
+ }
221
+ if (null != ParserSettings.this.on_message_complete) {
222
+ return ParserSettings.this.on_message_complete.cb(parser);
223
+ }
224
+ return 0;
225
+ }
226
+ };
227
+
228
+ }
229
+
230
+ private void attachCallbacks() {
231
+ // these are certainly set, because we mirror them ...
232
+ this.settings.on_message_begin = this._on_message_begin;
233
+ this.settings.on_path = this._on_path;
234
+ this.settings.on_query_string = this._on_query_string;
235
+ this.settings.on_url = this._on_url;
236
+ this.settings.on_fragment = this._on_fragment;
237
+ this.settings.on_header_field = this._on_header_field;
238
+ this.settings.on_header_value = this._on_header_value;
239
+ this.settings.on_headers_complete = this._on_headers_complete;
240
+ this.settings.on_body = this._on_body;
241
+ this.settings.on_message_complete = this._on_message_complete;
242
+ this.settings.on_error = this._on_error;
243
+ }
244
+ }
245
+ //import http_parser.HTTPException;
246
+ //public class ParserSettings extends http_parser.lolevel.ParserSettings{
247
+ //
248
+ //
249
+ //
250
+ //
251
+ // public HTTPCallback on_message_begin;
252
+ // public HTTPDataCallback on_path;
253
+ // public HTTPDataCallback on_query_string;
254
+ // public HTTPDataCallback on_url;
255
+ // public HTTPDataCallback on_fragment;
256
+ // public HTTPDataCallback on_header_field;
257
+ // public HTTPDataCallback on_header_value;
258
+ // public HTTPCallback on_headers_complete;
259
+ // public HTTPDataCallback on_body;
260
+ // public HTTPCallback on_message_complete;
261
+ // public HTTPErrorCallback on_error;
262
+ //
263
+ // void call_on_message_begin (HTTPParser p) {
264
+ // call_on(on_message_begin, p);
265
+ // }
266
+ //
267
+ // void call_on_message_complete (HTTPParser p) {
268
+ // call_on(on_message_complete, p);
269
+ // }
270
+ //
271
+ // // this one is a little bit different:
272
+ // // the current `position` of the buffer is the location of the
273
+ // // error, `ini_pos` indicates where the position of
274
+ // // the buffer when it was passed to the `execute` method of the parser, i.e.
275
+ // // using this information and `limit` we'll know all the valid data
276
+ // // in the buffer around the error we can use to print pretty error
277
+ // // messages.
278
+ // void call_on_error (HTTPParser p, String mes, ByteBuffer buf, int ini_pos) {
279
+ // if (null != on_error) {
280
+ // on_error.cb(p, mes, buf, ini_pos);
281
+ // }
282
+ // // if on_error gets called it MUST throw an exception, else the parser
283
+ // // will attempt to continue parsing, which it can't because it's
284
+ // // in an invalid state.
285
+ // throw new HTTPException(mes);
286
+ // }
287
+ //
288
+ // void call_on_header_field (HTTPParser p, ByteBuffer buf, int pos, int len) {
289
+ // call_on(on_header_field, p, buf, pos, len);
290
+ // }
291
+ // void call_on_query_string (HTTPParser p, ByteBuffer buf, int pos, int len) {
292
+ // call_on(on_query_string, p, buf, pos, len);
293
+ // }
294
+ // void call_on_fragment (HTTPParser p, ByteBuffer buf, int pos, int len) {
295
+ // call_on(on_fragment, p, buf, pos, len);
296
+ // }
297
+ // void call_on_path (HTTPParser p, ByteBuffer buf, int pos, int len) {
298
+ // call_on(on_path, p, buf, pos, len);
299
+ // }
300
+ // void call_on_header_value (HTTPParser p, ByteBuffer buf, int pos, int len) {
301
+ // call_on(on_header_value, p, buf, pos, len);
302
+ // }
303
+ // void call_on_url (HTTPParser p, ByteBuffer buf, int pos, int len) {
304
+ // call_on(on_url, p, buf, pos, len);
305
+ // }
306
+ // void call_on_body(HTTPParser p, ByteBuffer buf, int pos, int len) {
307
+ // call_on(on_body, p, buf, pos, len);
308
+ // }
309
+ // void call_on_headers_complete(HTTPParser p) {
310
+ // call_on(on_headers_complete, p);
311
+ // }
312
+ // void call_on (HTTPCallback cb, HTTPParser p) {
313
+ // // cf. CALLBACK2 macro
314
+ // if (null != cb) {
315
+ // cb.cb(p);
316
+ // }
317
+ // }
318
+ // void call_on (HTTPDataCallback cb, HTTPParser p, ByteBuffer buf, int pos, int len) {
319
+ // if (null != cb && -1 != pos) {
320
+ // cb.cb(p,buf,pos,len);
321
+ // }
322
+ // }
323
+ //}
@@ -1,35 +1,34 @@
1
- package http_parser.lolevel;
1
+ package http_parser;
2
2
 
3
3
  import java.nio.ByteBuffer;
4
- import http_parser.HTTPException;
5
4
 
6
5
  public class Util {
7
- public static String toString(HTTPParser p) {
8
- StringBuilder builder = new StringBuilder();
9
-
10
- // the stuff up to the break is ephermeral and only meaningful
11
- // while the parser is parsing. In general, this method is
12
- // probably only useful during debugging.
13
-
14
- builder.append("state :"); builder.append(p.state); builder.append("\n");
15
- builder.append("header_state :"); builder.append(p.header_state); builder.append("\n");
16
- builder.append("strict :"); builder.append(p.strict); builder.append("\n");
17
- builder.append("index :"); builder.append(p.index); builder.append("\n");
18
- builder.append("flags :"); builder.append(p.flags); builder.append("\n");
19
- builder.append("nread :"); builder.append(p.nread); builder.append("\n");
20
- builder.append("content_length :"); builder.append(p.content_length); builder.append("\n");
21
-
22
-
23
- builder.append("type :"); builder.append(p.type); builder.append("\n");
24
- builder.append("http_major :"); builder.append(p.http_major); builder.append("\n");
25
- builder.append("http_minor :"); builder.append(p.http_minor); builder.append("\n");
26
- builder.append("status_code :"); builder.append(p.status_code); builder.append("\n");
27
- builder.append("method :"); builder.append(p.method); builder.append("\n");
28
- builder.append("upgrade :"); builder.append(p.upgrade); builder.append("\n");
29
-
30
- return builder.toString();
31
-
32
- }
6
+ // public static String toString(http_parser.lolevel.HTTPParser p) {
7
+ // StringBuilder builder = new StringBuilder();
8
+ //
9
+ // // the stuff up to the break is ephermeral and only meaningful
10
+ // // while the parser is parsing. In general, this method is
11
+ // // probably only useful during debugging.
12
+ //
13
+ // builder.append("state :"); builder.append(p.state); builder.append("\n");
14
+ // builder.append("header_state :"); builder.append(p.header_state); builder.append("\n");
15
+ // builder.append("strict :"); builder.append(p.strict); builder.append("\n");
16
+ // builder.append("index :"); builder.append(p.index); builder.append("\n");
17
+ // builder.append("flags :"); builder.append(p.flags); builder.append("\n");
18
+ // builder.append("nread :"); builder.append(p.nread); builder.append("\n");
19
+ // builder.append("content_length :"); builder.append(p.content_length); builder.append("\n");
20
+ //
21
+ //
22
+ // builder.append("type :"); builder.append(p.type); builder.append("\n");
23
+ // builder.append("http_major :"); builder.append(p.http_major); builder.append("\n");
24
+ // builder.append("http_minor :"); builder.append(p.http_minor); builder.append("\n");
25
+ // builder.append("status_code :"); builder.append(p.status_code); builder.append("\n");
26
+ // builder.append("method :"); builder.append(p.method); builder.append("\n");
27
+ // builder.append("upgrade :"); builder.append(p.upgrade); builder.append("\n");
28
+ //
29
+ // return builder.toString();
30
+ //
31
+ // }
33
32
 
34
33
  public static String error (String mes, ByteBuffer b, int begining) {
35
34
  // the error message should look like this: