| OLD | NEW |
| 1 #import("dart:io"); | 1 #import("dart:io"); |
| 2 #import("dart:isolate"); | 2 #import("dart:isolate"); |
| 3 | 3 |
| 4 void sendData(List<int> data, int port) { | 4 void sendData(List<int> data, int port) { |
| 5 Socket socket = new Socket("127.0.0.1", port); | 5 Socket socket = new Socket("127.0.0.1", port); |
| 6 socket.onConnect = () { | 6 socket.onConnect = () { |
| 7 socket.onData = () { | 7 socket.onData = () { |
| 8 Expect.fail("No data response was expected"); | 8 Expect.fail("No data response was expected"); |
| 9 }; | 9 }; |
| 10 socket.outputStream.onNoPendingWrites = () { | 10 socket.outputStream.onNoPendingWrites = () { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 void testEarlyClose() { | 58 void testEarlyClose() { |
| 59 List<EarlyCloseTest> tests = new List<EarlyCloseTest>(); | 59 List<EarlyCloseTest> tests = new List<EarlyCloseTest>(); |
| 60 void add(Object data, String exception, {bool expectRequest: false}) { | 60 void add(Object data, String exception, {bool expectRequest: false}) { |
| 61 tests.add(new EarlyCloseTest(data, exception, expectRequest)); | 61 tests.add(new EarlyCloseTest(data, exception, expectRequest)); |
| 62 } | 62 } |
| 63 // The empty packet is valid. | 63 // The empty packet is valid. |
| 64 | 64 |
| 65 // Close while sending header | 65 // Close while sending header |
| 66 add("G", "Connection closed before full header was received"); | 66 String message = "Connection closed before full request header was received"; |
| 67 add("GET /", "Connection closed before full header was received"); | 67 add("G", message); |
| 68 add("GET / HTTP/1.1", "Connection closed before full header was received"); | 68 add("GET /", message); |
| 69 add("GET / HTTP/1.1\r\n", "Connection closed before full header was received")
; | 69 add("GET / HTTP/1.1", message); |
| 70 add("GET / HTTP/1.1\r\n", message); |
| 70 | 71 |
| 71 // Close while sending content | 72 // Close while sending content |
| 72 add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n", | 73 add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n", |
| 73 "Connection closed before full body was received", | 74 "Connection closed before full request body was received", |
| 74 expectRequest: true); | 75 expectRequest: true); |
| 75 add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n1", | 76 add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n1", |
| 76 "Connection closed before full body was received", | 77 "Connection closed before full request body was received", |
| 77 expectRequest: true); | 78 expectRequest: true); |
| 78 | 79 |
| 79 | 80 |
| 80 HttpServer server = new HttpServer(); | 81 HttpServer server = new HttpServer(); |
| 81 server.listen("127.0.0.1", 0); | 82 server.listen("127.0.0.1", 0); |
| 82 void runTest(Iterator it) { | 83 void runTest(Iterator it) { |
| 83 if (it.hasNext) { | 84 if (it.hasNext) { |
| 84 it.next().execute(server).then((_) => runTest(it)); | 85 it.next().execute(server).then((_) => runTest(it)); |
| 85 } else { | 86 } else { |
| 86 server.close(); | 87 server.close(); |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 runTest(tests.iterator()); | 90 runTest(tests.iterator()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void main() { | 93 void main() { |
| 93 testEarlyClose(); | 94 testEarlyClose(); |
| 94 } | 95 } |
| OLD | NEW |