| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library shelf_io_test; | 5 library shelf_io_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 test('Request is populated correctly', () { | 77 test('Request is populated correctly', () { |
| 78 var path = '/foo/bar?qs=value#anchor'; | 78 var path = '/foo/bar?qs=value#anchor'; |
| 79 | 79 |
| 80 _scheduleServer((request) { | 80 _scheduleServer((request) { |
| 81 expect(request.contentLength, 0); | 81 expect(request.contentLength, 0); |
| 82 expect(request.method, 'GET'); | 82 expect(request.method, 'GET'); |
| 83 | 83 |
| 84 var expectedUrl = 'http://localhost:$_serverPort$path'; | 84 var expectedUrl = 'http://localhost:$_serverPort$path'; |
| 85 expect(request.requestedUri, Uri.parse(expectedUrl)); | 85 expect(request.requestedUri, Uri.parse(expectedUrl)); |
| 86 | 86 |
| 87 expect(request.pathInfo, '/foo/bar'); | 87 expect(request.url.path, '/foo/bar'); |
| 88 expect(request.pathSegments, ['foo', 'bar']); | 88 expect(request.url.pathSegments, ['foo', 'bar']); |
| 89 expect(request.protocolVersion, '1.1'); | 89 expect(request.protocolVersion, '1.1'); |
| 90 expect(request.queryString, 'qs=value'); | 90 expect(request.url.query, 'qs=value'); |
| 91 expect(request.scriptName, ''); | 91 expect(request.scriptName, ''); |
| 92 | 92 |
| 93 return syncHandler(request); | 93 return syncHandler(request); |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 return schedule(() => http.get('http://localhost:$_serverPort$path')) | 96 return schedule(() => http.get('http://localhost:$_serverPort$path')) |
| 97 .then((response) { | 97 .then((response) { |
| 98 expect(response.statusCode, HttpStatus.OK); | 98 expect(response.statusCode, HttpStatus.OK); |
| 99 expect(response.body, 'Hello from /foo/bar'); | 99 expect(response.body, 'Hello from /foo/bar'); |
| 100 }); | 100 }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 122 | 122 |
| 123 return _scheduleGet().then((response) { | 123 return _scheduleGet().then((response) { |
| 124 expect(response.statusCode, 299); | 124 expect(response.statusCode, 299); |
| 125 expect(response.body, 'Hello from /'); | 125 expect(response.body, 'Hello from /'); |
| 126 }); | 126 }); |
| 127 }); | 127 }); |
| 128 | 128 |
| 129 test('custom request headers are received by the handler', () { | 129 test('custom request headers are received by the handler', () { |
| 130 _scheduleServer((request) { | 130 _scheduleServer((request) { |
| 131 expect(request.headers, containsPair('custom-header', 'client value')); | 131 expect(request.headers, containsPair('custom-header', 'client value')); |
| 132 |
| 133 // dart:io HttpServer splits multi-value headers into an array |
| 134 // validate that they are combined correctly |
| 135 expect(request.headers, containsPair('multi-header', 'foo,bar,baz')); |
| 132 return syncHandler(request); | 136 return syncHandler(request); |
| 133 }); | 137 }); |
| 134 | 138 |
| 135 var headers = { | 139 var headers = { |
| 136 'custom-header': 'client value' | 140 'custom-header': 'client value', |
| 141 'multi-header': 'foo,bar,baz' |
| 137 }; | 142 }; |
| 138 | 143 |
| 139 return _scheduleGet(headers: headers).then((response) { | 144 return _scheduleGet(headers: headers).then((response) { |
| 140 expect(response.statusCode, HttpStatus.OK); | 145 expect(response.statusCode, HttpStatus.OK); |
| 141 expect(response.body, 'Hello from /'); | 146 expect(response.body, 'Hello from /'); |
| 142 }); | 147 }); |
| 143 }); | 148 }); |
| 144 | 149 |
| 145 test('post with empty content', () { | 150 test('post with empty content', () { |
| 146 _scheduleServer((request) { | 151 _scheduleServer((request) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 213 |
| 209 var request = new http.Request('POST', | 214 var request = new http.Request('POST', |
| 210 Uri.parse('http://localhost:$_serverPort/')); | 215 Uri.parse('http://localhost:$_serverPort/')); |
| 211 | 216 |
| 212 if (headers != null) request.headers.addAll(headers); | 217 if (headers != null) request.headers.addAll(headers); |
| 213 if (body != null) request.body = body; | 218 if (body != null) request.body = body; |
| 214 | 219 |
| 215 return request.send(); | 220 return request.send(); |
| 216 }); | 221 }); |
| 217 } | 222 } |
| OLD | NEW |