| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:math'; | 5 import 'dart:math'; |
| 6 import 'dart:scalarlist'; | 6 import 'dart:scalarlist'; |
| 7 | 7 |
| 8 part '../../../sdk/lib/io/http.dart'; | 8 part '../../../sdk/lib/io/http.dart'; |
| 9 part '../../../sdk/lib/io/http_headers.dart'; | 9 part '../../../sdk/lib/io/http_headers.dart'; |
| 10 part '../../../sdk/lib/io/http_parser.dart'; | 10 part '../../../sdk/lib/io/http_parser.dart'; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 bool dataEndCalled; | 33 bool dataEndCalled; |
| 34 String method; | 34 String method; |
| 35 String uri; | 35 String uri; |
| 36 String version; | 36 String version; |
| 37 HttpHeaders headers; | 37 HttpHeaders headers; |
| 38 int contentLength; | 38 int contentLength; |
| 39 int bytesReceived; | 39 int bytesReceived; |
| 40 | 40 |
| 41 void reset() { | 41 void reset() { |
| 42 httpParser = new _HttpParser.requestParser(); | 42 httpParser = new _HttpParser.requestParser(); |
| 43 httpParser.requestStart = (m, u, v, h) { | 43 httpParser.requestStart = (m, u, v, h, b) { |
| 44 method = m; | 44 method = m; |
| 45 uri = u; | 45 uri = u; |
| 46 version = v; | 46 version = v; |
| 47 headers = h; | 47 headers = h; |
| 48 headersCompleteCalled = true; | 48 headersCompleteCalled = true; |
| 49 if (!chunked) { | 49 if (!chunked) { |
| 50 Expect.equals(expectedContentLength, httpParser.contentLength); | 50 Expect.equals(expectedContentLength, httpParser.contentLength); |
| 51 } else { | 51 } else { |
| 52 Expect.equals(-1, httpParser.contentLength); | 52 Expect.equals(-1, httpParser.contentLength); |
| 53 } | 53 } |
| 54 if (expectedHeaders != null) { | 54 if (expectedHeaders != null) { |
| 55 expectedHeaders.forEach( | 55 expectedHeaders.forEach( |
| 56 (String name, String value) => | 56 (String name, String value) => |
| 57 Expect.equals(value, headers[name][0])); | 57 Expect.equals(value, headers[name][0])); |
| 58 } | 58 } |
| 59 Expect.equals(upgrade, httpParser.upgrade); | 59 Expect.equals(upgrade, httpParser.upgrade); |
| 60 Expect.equals(connectionClose, !httpParser.persistentConnection); | 60 Expect.equals(connectionClose, !httpParser.persistentConnection); |
| 61 headersCompleteCalled = true; | 61 headersCompleteCalled = true; |
| 62 }; | 62 }; |
| 63 httpParser.responseStart = (s, r, v, h) { | 63 httpParser.responseStart = (s, r, v, h, b) { |
| 64 Expect.fail("Expected request"); | 64 Expect.fail("Expected request"); |
| 65 }; | 65 }; |
| 66 httpParser.dataReceived = (List<int> data) { | 66 httpParser.dataReceived = (List<int> data) { |
| 67 Expect.isTrue(headersCompleteCalled); | 67 Expect.isTrue(headersCompleteCalled); |
| 68 bytesReceived += data.length; | 68 bytesReceived += data.length; |
| 69 }; | 69 }; |
| 70 httpParser.dataEnd = (close) { | 70 httpParser.dataEnd = (close) { |
| 71 Expect.isFalse(close); | 71 Expect.isFalse(close); |
| 72 dataEndCalled = true; | 72 dataEndCalled = true; |
| 73 }; | 73 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 testWrite(requestData, 10); | 119 testWrite(requestData, 10); |
| 120 testWrite(requestData, 1); | 120 testWrite(requestData, 1); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static void _testParseInvalidRequest(String request) { | 123 static void _testParseInvalidRequest(String request) { |
| 124 _HttpParser httpParser; | 124 _HttpParser httpParser; |
| 125 bool errorCalled; | 125 bool errorCalled; |
| 126 | 126 |
| 127 void reset() { | 127 void reset() { |
| 128 httpParser = new _HttpParser.requestParser(); | 128 httpParser = new _HttpParser.requestParser(); |
| 129 httpParser.responseStart = (s, r) { Expect.fail("Expected request"); }; | 129 httpParser.responseStart = (s, r, v, h, b) { |
| 130 Expect.fail("Expected request"); |
| 131 }; |
| 130 httpParser.error = (e) { | 132 httpParser.error = (e) { |
| 131 errorCalled = true; | 133 errorCalled = true; |
| 132 }; | 134 }; |
| 133 httpParser.closed = () { }; | 135 httpParser.closed = () { }; |
| 134 | 136 |
| 135 errorCalled = false; | 137 errorCalled = false; |
| 136 } | 138 } |
| 137 | 139 |
| 138 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 140 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 139 if (chunkSize == -1) chunkSize = requestData.length; | 141 if (chunkSize == -1) chunkSize = requestData.length; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 String version; | 180 String version; |
| 179 HttpHeaders headers; | 181 HttpHeaders headers; |
| 180 int contentLength; | 182 int contentLength; |
| 181 int bytesReceived; | 183 int bytesReceived; |
| 182 | 184 |
| 183 void reset() { | 185 void reset() { |
| 184 httpParser = new _HttpParser.responseParser(); | 186 httpParser = new _HttpParser.responseParser(); |
| 185 if (responseToMethod != null) { | 187 if (responseToMethod != null) { |
| 186 httpParser.responseToMethod = responseToMethod; | 188 httpParser.responseToMethod = responseToMethod; |
| 187 } | 189 } |
| 188 httpParser.requestStart = (m, u, v, h) { | 190 httpParser.requestStart = (m, u, v, h, b) { |
| 189 Expect.fail("Expected response"); | 191 Expect.fail("Expected response"); |
| 190 }; | 192 }; |
| 191 httpParser.responseStart = (s, r, v, h) { | 193 httpParser.responseStart = (s, r, v, h, b) { |
| 192 statusCode = s; | 194 statusCode = s; |
| 193 reasonPhrase = r; | 195 reasonPhrase = r; |
| 194 version = v; | 196 version = v; |
| 195 headers = h; | 197 headers = h; |
| 196 Expect.isFalse(headersCompleteCalled); | 198 Expect.isFalse(headersCompleteCalled); |
| 197 if (!chunked && !close) { | 199 if (!chunked && !close) { |
| 198 Expect.equals(expectedContentLength, httpParser.contentLength); | 200 Expect.equals(expectedContentLength, httpParser.contentLength); |
| 199 } else { | 201 } else { |
| 200 Expect.equals(-1, httpParser.contentLength); | 202 Expect.equals(-1, httpParser.contentLength); |
| 201 } | 203 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 testWrite(responseData, 10); | 271 testWrite(responseData, 10); |
| 270 testWrite(responseData, 1); | 272 testWrite(responseData, 1); |
| 271 } | 273 } |
| 272 | 274 |
| 273 static void _testParseInvalidResponse(String response, [bool close = false]) { | 275 static void _testParseInvalidResponse(String response, [bool close = false]) { |
| 274 _HttpParser httpParser; | 276 _HttpParser httpParser; |
| 275 bool errorCalled; | 277 bool errorCalled; |
| 276 | 278 |
| 277 void reset() { | 279 void reset() { |
| 278 httpParser = new _HttpParser.responseParser(); | 280 httpParser = new _HttpParser.responseParser(); |
| 279 httpParser.requestStart = (m, u) => Expect.fail("Expected response"); | 281 httpParser.requestStart = (m, u, v, h, b) { |
| 282 Expect.fail("Expected response"); |
| 283 }; |
| 280 httpParser.error = (e) => errorCalled = true; | 284 httpParser.error = (e) => errorCalled = true; |
| 281 httpParser.closed = () { }; | 285 httpParser.closed = () { }; |
| 282 | 286 |
| 283 errorCalled = false; | 287 errorCalled = false; |
| 284 } | 288 } |
| 285 | 289 |
| 286 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 290 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 287 if (chunkSize == -1) chunkSize = requestData.length; | 291 if (chunkSize == -1) chunkSize = requestData.length; |
| 288 reset(); | 292 reset(); |
| 289 for (int pos = 0; | 293 for (int pos = 0; |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 0123456789012345678901234567890\r | 857 0123456789012345678901234567890\r |
| 854 0\r\n\r\n"""; | 858 0\r\n\r\n"""; |
| 855 _testParseInvalidResponse(response); | 859 _testParseInvalidResponse(response); |
| 856 } | 860 } |
| 857 } | 861 } |
| 858 | 862 |
| 859 | 863 |
| 860 void main() { | 864 void main() { |
| 861 HttpParserTest.runAllTests(); | 865 HttpParserTest.runAllTests(); |
| 862 } | 866 } |
| OLD | NEW |