|
| 1 | +package http_parser.lolevel; |
| 2 | + |
| 3 | +import java.nio.*; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | +import static http_parser.lolevel.Util.*; |
| 7 | +import http_parser.*; |
| 8 | + |
| 9 | +import primitive.collection.ByteList; |
| 10 | + |
| 11 | +public class Requests { |
| 12 | + |
| 13 | + static void test_simple(String req, boolean should_pass) { |
| 14 | + HTTPParser parser = new HTTPParser(ParserType.HTTP_REQUEST); |
| 15 | + ByteBuffer buf = buffer(req); |
| 16 | + boolean passed = false; |
| 17 | + int read = 0; |
| 18 | + try { |
| 19 | + parser.execute(Util.SETTINGS_NULL, buf); |
| 20 | + passed = (read == req.length()); |
| 21 | + read = parser.execute(Util.SETTINGS_NULL, Util.empty()); |
| 22 | + passed &= (0 == read); |
| 23 | + } catch (Throwable t) { |
| 24 | + passed = false; |
| 25 | + } |
| 26 | + check(passed == should_pass); |
| 27 | + } |
| 28 | + static void simple_tests() { |
| 29 | + test_simple("hello world", false); |
| 30 | + test_simple("GET / HTP/1.1\r\n\r\n", false); |
| 31 | + |
| 32 | + test_simple("ASDF / HTTP/1.1\r\n\r\n", false); |
| 33 | + test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", false); |
| 34 | + test_simple("GETA / HTTP/1.1\r\n\r\n", false); |
| 35 | + } |
| 36 | + |
| 37 | + public static void test () { |
| 38 | + |
| 39 | + simple_tests(); |
| 40 | + |
| 41 | + List<Message> all = TestLoaderNG.load("tests.dumped"); |
| 42 | + List<Message> requests = new LinkedList<Message>(); |
| 43 | + for (Message m : all) { |
| 44 | + if (ParserType.HTTP_REQUEST == m.type) { |
| 45 | + requests.add(m); |
| 46 | + } |
| 47 | + } |
| 48 | + for (Message m : requests) { |
| 49 | + test_message(m); |
| 50 | + } |
| 51 | + |
| 52 | + for (int i = 0; i!= requests.size(); ++i) { |
| 53 | + if (!requests.get(i).should_keep_alive) continue; |
| 54 | + for (int j = 0; j!=requests.size(); ++j) { |
| 55 | + if (!requests.get(j).should_keep_alive) continue; |
| 56 | + for (int k = 0; k!= requests.size(); ++k) { |
| 57 | + test_multiple3(requests.get(i), requests.get(j), requests.get(k)); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + // postpone test_scan |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +} |
0 commit comments