http_parser.rb 0.5.1-x86-mswin32-60 → 0.5.2-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) 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-java/LICENSE-MIT +26 -1
  6. data/ext/ruby_http_parser/vendor/http-parser-java/README.md +23 -143
  7. data/ext/ruby_http_parser/vendor/http-parser-java/TODO +3 -0
  8. data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +74 -0
  9. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +115 -61
  10. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +19 -3
  11. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +8 -0
  12. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +34 -0
  13. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +12 -0
  14. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +4 -2
  15. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +64 -52
  16. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +5 -0
  17. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +323 -0
  18. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/{lolevel/Util.java → Util.java} +27 -28
  19. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +259 -85
  20. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +1 -0
  21. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +324 -0
  22. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +69 -0
  23. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +51 -0
  24. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +15 -0
  25. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +47 -0
  26. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +183 -447
  27. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +61 -0
  28. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +2 -1
  29. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +26 -0
  30. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +165 -0
  31. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +58 -0
  32. data/ext/ruby_http_parser/vendor/http-parser-java/test.c +232 -29
  33. data/ext/ruby_http_parser/vendor/http-parser-java/test_permutations +1 -1
  34. data/ext/ruby_http_parser/vendor/http-parser-java/test_unit +1 -1
  35. data/ext/ruby_http_parser/vendor/http-parser-java/test_utf8 +1 -0
  36. data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +154 -7
  37. data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +17 -0
  38. data/ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT +1 -1
  39. data/ext/ruby_http_parser/vendor/http-parser/http_parser.c +52 -10
  40. data/ext/ruby_http_parser/vendor/http-parser/http_parser.h +3 -1
  41. data/ext/ruby_http_parser/vendor/http-parser/test.c +89 -3
  42. data/http_parser.rb.gemspec +8 -2
  43. data/lib/http_parser.rb +17 -0
  44. data/spec/parser_spec.rb +97 -6
  45. data/tasks/compile.rake +3 -1
  46. metadata +83 -20
  47. data/ext/ruby_http_parser/vendor/http-parser-java/CONTRIBUTIONS +0 -4
@@ -0,0 +1,15 @@
1
+ package http_parser.lolevel;
2
+
3
+
4
+ public class Test {
5
+ public static void main (String [] args) {
6
+ UnitTest.test();
7
+ TestHeaderOverflowError.test();
8
+ TestNoOverflowLongBody.test();
9
+ Responses.test();
10
+ //Requests.test();
11
+ Upgrade.test();
12
+ WrongContentLength.test();
13
+ }
14
+
15
+ }
@@ -0,0 +1,47 @@
1
+ package http_parser.lolevel;
2
+
3
+ import java.nio.*;
4
+
5
+ import static http_parser.lolevel.Util.*;
6
+
7
+ public class TestHeaderOverflowError {
8
+
9
+ public static void test (http_parser.ParserType type) {
10
+ HTTPParser parser = new HTTPParser(type);
11
+ ByteBuffer buf = getBytes(type);
12
+
13
+ int numbytes = buf.limit();
14
+
15
+ parser.execute(Util.SETTINGS_NULL, buf);
16
+
17
+ check(numbytes == buf.position());
18
+
19
+ buf = buffer("header-key: header-value\r\n");
20
+ numbytes = buf.limit();
21
+ for (int i = 0; i!= 1000; ++i) {
22
+ parser.execute(Util.SETTINGS_NULL, buf);
23
+ check(numbytes == buf.position());
24
+
25
+ buf.rewind();
26
+
27
+ }
28
+ }
29
+
30
+ static ByteBuffer getBytes (http_parser.ParserType type) {
31
+ if (http_parser.ParserType.HTTP_BOTH == type) {
32
+ throw new RuntimeException("only HTTP_REQUEST and HTTP_RESPONSE");
33
+ }
34
+
35
+ if (http_parser.ParserType.HTTP_REQUEST == type) {
36
+ return buffer("GET / HTTP/1.1\r\n");
37
+ }
38
+ return buffer("HTTP/1.0 200 OK\r\n");
39
+ }
40
+
41
+ public static void test () {
42
+ test(http_parser.ParserType.HTTP_REQUEST);
43
+ test(http_parser.ParserType.HTTP_RESPONSE);
44
+ }
45
+
46
+
47
+ }
@@ -20,6 +20,10 @@ package http_parser.lolevel;
20
20
 
21
21
  import java.io.FileReader;
22
22
  import java.io.BufferedReader;
23
+ import java.io.StringReader;
24
+ import java.io.Reader;
25
+ import java.io.Reader;
26
+ import java.io.IOException;
23
27
 
24
28
  import java.util.*;
25
29
  import java.util.regex.*;
@@ -30,458 +34,190 @@ import http_parser.HTTPMethod;
30
34
  import http_parser.ParserType;
31
35
 
32
36
  public class TestLoaderNG {
33
- String fn;
34
- public TestLoaderNG(String filename) {
35
- this.fn = filename;
36
- }
37
- static void p(Object o) {
38
- System.out.println(o);
39
- }
40
- public List<Test> load () throws Throwable {
41
- List<Test> list = new LinkedList<Test>();
42
- BufferedReader buf = new BufferedReader(new FileReader(fn));
43
- String line = null;
44
- Test curr = new Test();
45
- Pattern pattern = Pattern.compile("(\\S+)\\s*:(.*)");
46
- while (null != (line = buf.readLine()) ){
47
- if ("".equals(line.trim())) {
48
- list.add (curr);
49
- curr = new Test();
50
- continue;
51
- }
52
- Matcher m = pattern.matcher(line);
53
- if (m.matches()) {
54
- // you can not be fucking serious!?
55
- // this has got to be the most retarded regex
56
- // interface in the history of the world ...
57
- // (though I'm sure there's worse c++ regexp libs...)
58
- MatchResult r = m.toMatchResult();
59
- String key = r.group(1).trim();
60
- String value = r.group(2).trim();
61
- if ("name".equals(key)) {curr.name = value;}
62
- else if ("raw".equals(key)) {curr.raw = toByteArray(value);} //!
63
- else if ("type".equals(key)) {curr.type = ParserType.parse(value);}
64
- else if ("method".equals(key)) {curr.method = HTTPMethod.parse(value);}
65
- else if ("status_code".equals(key)) {curr.status_code = Integer.parseInt(value);}
66
- else if ("request_path".equals(key)) {curr.request_path = value;}
67
- else if ("request_url".equals(key)) {curr.request_url = value;}
68
-
69
- else if ("fragment".equals(key)) {curr.fragment = value;}
70
- else if ("query_string".equals(key)) {curr.query_string = value;}
71
- else if ("body".equals(key)) {curr.body = toByteArray(value);} //!
72
- else if ("body_size".equals(key)) {curr.body_size = Integer.parseInt(value);}
73
- else if (key.startsWith("header")) {
74
- String [] h = getHeader(value);
75
- curr.header.put(h[0], h[1]);
76
- }
77
- else if ("should_keep_alive".equals(key))
78
- {curr.should_keep_alive = (1 == Integer.parseInt(value));}
79
- else if ("upgrade".equals(key)) {curr.upgrade = (1 == Integer.parseInt(value));}
80
- else if ("http_major".equals(key)) {curr.http_major = Integer.parseInt(value);}
81
- else if ("http_minor".equals(key)) {curr.http_minor = Integer.parseInt(value);}
82
- } else {
83
- p("WTF?"+line);
84
- }
85
-
86
- }
87
- return list;
88
- }
89
-
90
- String [] getHeader(String value) {
91
- // { "Host": "0.0.0.0=5000"}
92
- Pattern p = Pattern.compile("\\{ ?\"([^\"]*)\": ?\"([^\"]*)\"}");
93
- Matcher m = p.matcher(value);
94
- if (!m.matches()) {
95
- p(value);
96
- throw new RuntimeException("something wrong");
97
- }
98
- String [] result = new String[2];
99
- MatchResult r = m.toMatchResult();
100
- result[0] = r.group(1).trim();
101
- result[1] = r.group(2).trim();
102
- return result;
103
- }
104
-
105
- static final byte BSLASH = 0x5c;
106
- static final byte QUOT = 0x22;
107
- static final byte CR = 0x0d;
108
- static final byte LF = 0x0a;
109
- static final byte n = 0x6e;
110
- static final byte r = 0x72;
111
-
112
- static final Byte[] JAVA_GENERICS_ROCK_HARD = new Byte[0];
113
-
114
-
115
- static byte [] toByteArray (String quotedString) {
116
- ArrayList<Byte> bytes = new ArrayList<Byte>();
117
- String s = quotedString.substring(1, quotedString.length()-1);
118
- byte [] byts = s.getBytes(java.nio.charset.Charset.forName("ASCII"));
119
- boolean escaped = false;
120
- for (byte b : byts) {
121
- switch (b) {
122
- case BSLASH:
123
- escaped = true;
124
- break;
125
- case n:
126
- if (escaped) {
127
- bytes.add(LF);
128
- escaped = false;
129
- } else {
130
- bytes.add(b);
131
- }
132
- break;
133
- case r:
134
- if (escaped) {
135
- escaped = false;
136
- bytes.add(CR);
137
- } else {
138
- bytes.add(b);
139
- }
140
- break;
141
- case QUOT:
142
- escaped = false;
143
- bytes.add(QUOT);
144
- break;
145
- default:
146
- bytes.add(b);
147
- }
148
-
149
- }
150
- //Byte [] fuckyou = bytes.toArray(JAVA_GENERICS_ROCK_HARD);
151
- //return (byte[])fuckyou;
152
- byts = new byte[bytes.size()];
153
- int i = 0;
154
- for (Byte b : bytes) {
155
- byts[i++]=b;
156
- // OMG, WFTBBQ!?
157
- }
158
- return byts;
159
- }
160
-
161
- public static void main(String [] args) throws Throwable {
162
- TestLoaderNG l = new TestLoaderNG(args[0]);
163
- List<Test> ts = l.load();
164
-
165
- for (Test t : ts) {
166
- t.execute_permutations();
167
- // t.execute();
168
- // System.exit(0);
169
- }
170
- }
171
-
172
-
173
- class Test {
174
- String name;
175
- byte [] raw;
176
- ParserType type;
177
- HTTPMethod method;
178
- int status_code;
179
- String request_path; // byte [] ?
180
- String request_url;
181
- String fragment ;
182
- String query_string;
183
- byte [] body;
184
- int body_size;
185
- Map<String,String> header;
186
- boolean should_keep_alive;
187
- boolean upgrade;
188
- int http_major;
189
- int http_minor;
190
-
191
- boolean message_begin_called;
192
- boolean message_complete_called;
193
- boolean headers_complete_called;
194
-
195
-
196
- Map<String,String> parsed_header;
197
- String currHField;
198
- String currHValue;
199
- byte [] pbody;
200
-
201
- public String toString() {
202
- StringBuilder b = new StringBuilder();
203
- b.append("type: "); b.append(type);b.append("\n");
204
- b.append("method: "); b.append(method);b.append("\n");
205
- b.append("status_code: "); b.append(status_code);b.append("\n");
206
- b.append("request_path: "); b.append(request_path);b.append("\n");
207
- b.append("request_url: "); b.append(request_url);b.append("\n");
208
- b.append("fragment: "); b.append(fragment);b.append("\n");
209
- b.append("query_string: "); b.append(query_string);b.append("\n");
210
- b.append("body:\n"); b.append(new String(body));b.append("\n");
211
- b.append("should_keep_alive: "); b.append(should_keep_alive);b.append("\n");
212
- b.append("upgrade: "); b.append(upgrade);b.append("\n");
213
- b.append("http_major: "); b.append(http_major);b.append("\n");
214
- b.append("http_minor: "); b.append(http_minor);b.append("\n");
215
- b.append("message_complete_called: "); b.append(message_complete_called);b.append("\n");
216
- return b.toString();
37
+ String fn;
38
+ public TestLoaderNG(String filename) {
39
+ this.fn = filename;
40
+ }
41
+ static void p(Object o) {
42
+ System.out.println(o);
43
+ }
44
+ public static List<Message> load (String fn) {
45
+ List<Message> list = null;
46
+ try {
47
+ BufferedReader buf = new BufferedReader(new FileReader(fn));
48
+ list = load(buf);
49
+ } catch (Throwable t) {
50
+ throw new RuntimeException(t);
217
51
  }
52
+ return list;
53
+
54
+ }
55
+ public static Message parse (String message) {
56
+ List<Message> list = load(new BufferedReader(new StringReader(message)));
57
+ if (null == list || 0 == list.size() ) {
58
+ return null;
59
+ }
60
+ return list.get(0);
61
+ }
62
+
63
+ public static List<Message> load (BufferedReader buf) {
64
+ List<Message> list = new LinkedList<Message>();
65
+ String line = null;
66
+ Message curr = new Message();
67
+ Pattern pattern = Pattern.compile("(\\S+)\\s*:(.*)");
68
+ try {
69
+ while (null != (line = buf.readLine()) ){
70
+ if ("".equals(line.trim())) {
71
+ list.add (curr);
72
+ curr = new Message();
73
+ continue;
74
+ }
75
+ Matcher m = pattern.matcher(line);
76
+ if (m.matches()) {
77
+ // you can not be fucking serious!?
78
+ // this has got to be the most retarded regex
79
+ // interface in the history of the world ...
80
+ // (though I'm sure there's worse c++ regexp libs...)
81
+ MatchResult r = m.toMatchResult();
82
+ String key = r.group(1).trim();
83
+ String value = r.group(2).trim();
84
+ if ("name".equals(key)) {curr.name = value;}
85
+ else if ("raw".equals(key)) {curr.raw = toByteArray(value);} //!
86
+ else if ("type".equals(key)) {curr.type = ParserType.parse(value);}
87
+ else if ("method".equals(key)) {curr.method = HTTPMethod.parse(value);}
88
+ else if ("status_code".equals(key)) {curr.status_code = Integer.parseInt(value);}
89
+ else if ("request_path".equals(key)) {curr.request_path = value;}
90
+ else if ("request_url".equals(key)) {curr.request_url = value;}
91
+
92
+ else if ("fragment".equals(key)) {curr.fragment = value;}
93
+ else if ("query_string".equals(key)) {curr.query_string = value;}
94
+ else if ("body".equals(key)) {curr.body = toByteArray(value);} //!
95
+ else if ("body_size".equals(key)) {curr.body_size = Integer.parseInt(value);}
96
+ else if (key.startsWith("header")) {
97
+ String [] h = getHeader(value);
98
+ curr.header.put(h[0], h[1]);
99
+ }
100
+ else if ("should_keep_alive".equals(key))
101
+ {curr.should_keep_alive = (1 == Integer.parseInt(value));}
102
+ else if ("upgrade".equals(key)) {curr.upgrade = (1 == Integer.parseInt(value));}
103
+ else if ("http_major".equals(key)) {curr.http_major = Integer.parseInt(value);}
104
+ else if ("http_minor".equals(key)) {curr.http_minor = Integer.parseInt(value);}
105
+ } else {
106
+ p("WTF?"+line);
107
+ }
218
108
 
219
- Test () {
220
- this.header = new HashMap<String, String>();
221
- reset();
222
- }
223
- /*
224
- *prepare this Test Instance for reuse.
225
- * */
226
- void reset () {
227
- this.parsed_header = new HashMap<String, String>();
228
- this.pbody = null;
229
-
109
+ }
110
+ } catch (Throwable t) {
111
+ throw new RuntimeException(t);
230
112
  }
231
- void check (boolean val, String mes) {
232
- if (!val) {
233
- //p(name+" : "+mes);
234
- throw new RuntimeException(name+" : "+mes);
235
- }
236
- }
237
-
238
- String str (ByteBuffer b, int pos, int len) {
239
- byte [] by = new byte[len];
240
- int saved = b.position();
241
- b.position(pos);
242
- b.get(by);
243
- b.position(saved);
244
- return new String(by);
245
- }
246
-
247
- HTTPDataCallback getCB (final String value, final String mes, final TestSettings settings) {
248
- return new HTTPDataCallback() {
249
- public int cb (HTTPParser p, ByteBuffer b, int pos, int len){
250
- // if ("url".equals(mes)){
251
- // p("pos"+pos);
252
- // p("len"+len);
253
- // if (8==pos && 5 == len && "connect request".equals(name)) {
254
- // //throw new RuntimeException(name);
255
- // }
256
- // }
257
- String str = str(b, pos, len);
258
- String prev_val = settings.map.get(mes);
259
- settings.map.put(mes, prev_val + str);
260
- //check(value.equals(str), "incorrect "+mes+": "+str);
261
- if (-1 == pos) {
262
- throw new RuntimeException("he?");
263
- }
264
- return 0;
265
- }
266
- };
267
- }
268
-
269
- void execute () {
270
- p(name);
271
- ByteBuffer buf = ByteBuffer.wrap(raw);
272
- HTTPParser p = new HTTPParser();
273
- TestSettings s = settings();
274
-
275
-
276
-
277
- p.execute(s, buf);
278
- if (!s.success) {
279
- throw new RuntimeException("Test: "+name+"failed");
280
- }
281
- } // execute
282
-
283
- void execute_permutations() {
284
- /*
285
- |-|---------------|
286
- |--|--------------|
287
- |---|-------------|
288
- (...)
289
- |---------------|-|
290
- |-----------------|
291
- */
292
- p(name);
293
- for (int i = 2; i != raw.length; ++i) {
294
- // p(i);
295
- HTTPParser p = new HTTPParser();
296
- TestSettings s = settings();
297
- ByteBuffer buf = ByteBuffer.wrap(raw);
298
- int olimit = buf.limit();
299
- buf.limit(i);
300
-
301
- parse(p,s,buf);
302
-
303
- buf.position(i);
304
- buf.limit(olimit);
305
-
306
- parse(p,s,buf);
307
- parse(p,s,buf);
308
-
309
- if (!s.success) {
310
- p(this);
311
- throw new RuntimeException("Test: "+name+" failed");
312
- }
313
- reset();
314
- }
315
- //System.exit(0);
316
- } // execute_permutations
317
- void parse(HTTPParser p, ParserSettings s, ByteBuffer b) {
318
- //p("About to parse: "+b.position() + "->" + b.limit());
319
- p.execute(s, b);
320
- }
321
-
322
- TestSettings settings() {
323
- final TestSettings s = new TestSettings();
324
- s.on_path = getCB(request_path, "path", s);
325
- s.on_query_string = getCB(query_string, "query_string", s);
326
- s.on_url = getCB(request_url, "url", s);
327
- s.on_fragment = getCB(fragment, "fragment", s);
328
- s.on_message_begin = new HTTPCallback() {
329
- public int cb (HTTPParser p) {
330
- message_begin_called = true;
331
- return -1;
332
- }
333
- };
334
- s.on_header_field = new HTTPDataCallback() {
335
- public int cb (HTTPParser p, ByteBuffer b, int pos, int len){
336
- if (null != currHValue && null == currHField) {
337
- throw new RuntimeException(name+": shouldn't happen");
338
- }
339
- if (null != currHField) {
340
- if (null == currHValue) {
341
- currHField += str(b,pos,len);
342
- return 0;
343
- } else {
344
- parsed_header.put(currHField, currHValue);
345
- currHField = null;
346
- currHValue = null;
347
- }
348
- }
349
- currHField = str(b,pos,len);
350
- return 0;
351
- }
352
- };
353
- s.on_header_value = new HTTPDataCallback() {
354
- public int cb (HTTPParser p, ByteBuffer b, int pos, int len){
355
- if (null == currHField) {
356
- throw new RuntimeException(name+" :shouldn't happen field");
357
- }
358
- if (null == currHValue) {
359
- currHValue = str(b,pos,len);
113
+ return list;
114
+ }
115
+
116
+ static String [] getHeader(String value) {
117
+ // { "Host": "0.0.0.0=5000"}
118
+ Pattern p = Pattern.compile("\\{ ?\"([^\"]*)\": ?\"(.*)\"}");
119
+ Matcher m = p.matcher(value);
120
+ if (!m.matches()) {
121
+ p(value);
122
+ throw new RuntimeException("something wrong");
123
+ }
124
+ String [] result = new String[2];
125
+ MatchResult r = m.toMatchResult();
126
+ result[0] = r.group(1).trim();
127
+ result[1] = r.group(2); //.trim();
128
+ return result;
129
+ }
130
+
131
+ static final byte BSLASH = 0x5c;
132
+ static final byte QUOT = 0x22;
133
+ static final byte CR = 0x0d;
134
+ static final byte LF = 0x0a;
135
+ static final byte n = 0x6e;
136
+ static final byte r = 0x72;
137
+
138
+ static final Byte[] JAVA_GENERICS_ROCK_HARD = new Byte[0];
139
+
140
+
141
+ static byte [] toByteArray (String quotedString) {
142
+ ArrayList<Byte> bytes = new ArrayList<Byte>();
143
+ String s = quotedString.substring(1, quotedString.length()-1);
144
+ byte [] byts = s.getBytes(java.nio.charset.Charset.forName("UTF8"));
145
+ boolean escaped = false;
146
+ for (byte b : byts) {
147
+ switch (b) {
148
+ case BSLASH:
149
+ escaped = true;
150
+ break;
151
+ case n:
152
+ if (escaped) {
153
+ bytes.add(LF);
154
+ escaped = false;
360
155
  } else {
361
- currHValue += str(b, pos, len);
156
+ bytes.add(b);
362
157
  }
363
- return 0;
364
- }
365
- };
366
- s.on_headers_complete = new HTTPCallback() {
367
- public int cb (HTTPParser p) {
368
- headers_complete_called = true;
369
- String parsed_path = s.map.get("path");
370
- String parsed_query = s.map.get("query_string");
371
- String parsed_url = s.map.get("url");
372
- String parsed_frag = s.map.get("fragment");
373
-
374
- if (!request_path.equals(parsed_path)) {
375
- throw new RuntimeException(name+": invalid path: "+parsed_path+" should be: "+request_path);
376
- }
377
- if (!query_string.equals(parsed_query)) {
378
- throw new RuntimeException(name+": invalid query: "+parsed_query+" should be: "+query_string);
379
- }
380
- if (!request_url.equals(parsed_url)) {
381
- throw new RuntimeException(">"+name+"<: invalid url: >"+parsed_url+"< should be: >"+request_url+"<");
382
- }
383
- if (!fragment.equals(parsed_frag)) {
384
- throw new RuntimeException(name+": invalid fragement: "+parsed_frag+" should be: "+fragment);
385
- }
386
- if (null != currHValue || null != currHField) {
387
- if (null == currHField || null == currHValue) {
388
- throw new RuntimeException("shouldn't happen");
389
- }
390
- }
391
- if (null != currHField) {
392
- parsed_header.put(currHField, currHValue);
393
- currHField = null;
394
- currHValue = null;
395
- }
396
-
397
-
398
- return 0;
399
- }
400
- };
401
- // s.on_headers_complete = new HTTPCallback() {
402
- // public int cb (HTTPParser p) {
403
- // p("Complete:"+name);
404
- // return 0;
405
- // }
406
- // };
407
-
408
- s.on_body = new HTTPDataCallback() {
409
- public int cb (HTTPParser p, ByteBuffer b, int pos, int len){
410
- int l = pbody == null ? len : len + pbody.length;
411
- int off = pbody == null ? 0 : pbody.length;
412
- byte [] nbody = new byte[l];
413
-
414
- if (null != pbody) {
415
- System.arraycopy(pbody, 0, nbody, 0, pbody.length);
416
- }
417
-
418
- int saved = b.position();
419
- b.position(pos);
420
- b.get(nbody, off, len);
421
- b.position(saved);
422
- pbody = nbody;
423
- return 0;
424
- }
425
- };
426
-
427
- s.on_message_complete = new HTTPCallback() {
428
- public int cb(HTTPParser p) {
429
- message_complete_called = true;
430
- if ( p.http_minor != http_minor
431
- || p.http_major != http_major
432
- || p.status_code != status_code ) {
433
-
434
- throw new RuntimeException("major/minor/status_code mismatch");
435
- }
158
+ break;
159
+ case r:
160
+ if (escaped) {
161
+ escaped = false;
162
+ bytes.add(CR);
163
+ } else {
164
+ bytes.add(b);
165
+ }
166
+ break;
167
+ case QUOT:
168
+ escaped = false;
169
+ bytes.add(QUOT);
170
+ break;
171
+ default:
172
+ bytes.add(b);
173
+ }
436
174
 
437
- //check headers
175
+ }
438
176
 
439
- if (header.keySet().size() != parsed_header.keySet().size()) {
440
- p(parsed_header);
441
- throw new RuntimeException(name+": different amount of headers");
442
- }
443
- for (String key : header.keySet()) {
444
- String pvalue = parsed_header.get(key);
445
- if (!header.get(key).equals(pvalue)) {
446
- throw new RuntimeException(name+" : different values for :"+key+" is >"+pvalue+"< should: >"+header.get(key)+"<");
447
- }
448
- }
449
- //check body
450
- if (null == pbody && (null == body || body.length == 0 || body.length == 1)) {
451
- s.success = true;
452
- return 0;
453
- }
454
- if (null == pbody) {
455
- throw new RuntimeException(name+": no body, should be: "+new String(body));
456
- }
457
- if (pbody.length != body.length) {
458
- p(pbody.length);
459
- p(body.length);
460
- p(new String(pbody));
461
- p(new String(body));
462
- throw new RuntimeException(name+": incorrect body length");
463
- }
464
- for (int i = 0 ; i!= body.length; ++i) {
465
- if (pbody[i] != body[i]) {
466
- throw new RuntimeException("different body");
467
- }
468
- }
469
- s.success = true;
470
- return 0;
471
- }
472
- };
473
- return s;
474
- } // settings
475
- }
476
- class TestSettings extends ParserSettings {
477
- public boolean success;
478
- Map<String, String> map;
479
- TestSettings () {
480
- map = new HashMap<String, String>();
481
- map.put("path", "");
482
- map.put("query_string", "");
483
- map.put("url", "");
484
- map.put("fragment", "");
485
- }
486
- }
177
+ byts = new byte[bytes.size()];
178
+ int i = 0;
179
+ for (Byte b : bytes) {
180
+ byts[i++]=b;
181
+ }
182
+ return byts;
183
+ }
184
+
185
+ public static void main(String [] args) throws Throwable {
186
+ //TestLoaderNG l = new TestLoaderNG(args[0]);
187
+ List<Message> ts = load(args[0]);
188
+ for (Message t : ts) {
189
+ // for (int i =0; i!= t.raw.length; ++i) {
190
+ // p(i+":"+t.raw[i]);
191
+ // }
192
+ try {
193
+ t.execute_permutations();
194
+ } catch (Throwable th) {
195
+ p("failed: "+t.name);
196
+ }
197
+ // t.execute();
198
+ // System.exit(0);
199
+ }
200
+ }
201
+
202
+ class Header {
203
+ String field;
204
+ String value;
205
+ }
206
+ enum LastHeader {
207
+ NONE
208
+ ,FIELD
209
+ ,VALUE
210
+ }
211
+
212
+ static class TestSettings extends ParserSettings {
213
+ public boolean success;
214
+ Map<String, String> map;
215
+ TestSettings () {
216
+ map = new HashMap<String, String>();
217
+ map.put("path", "");
218
+ map.put("query_string", "");
219
+ map.put("url", "");
220
+ map.put("fragment", "");
221
+ }
222
+ }
487
223
  }