OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import 'dart:async'; | 10 import 'dart:async'; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 (data) {}, | 141 (data) {}, |
142 onError: (error) => errors++, | 142 onError: (error) => errors++, |
143 onDone: () { | 143 onDone: () { |
144 Expect.equals(1, errors); | 144 Expect.equals(1, errors); |
145 asyncEnd(); | 145 asyncEnd(); |
146 }); | 146 }); |
147 }); | 147 }); |
148 }); | 148 }); |
149 } | 149 } |
150 | 150 |
151 void testPostEmptyRequest() { | |
152 HttpServer.bind("127.0.0.1", 0).then((server) { | |
153 server.listen((request) { | |
154 request.pipe(request.response); | |
155 }); | |
156 | |
157 var client = new HttpClient(); | |
158 client.post("127.0.0.1", server.port, "/") | |
159 .then((request) => request.close()) | |
160 .then((response) { | |
161 response.listen((data) {}, onDone: server.close); | |
162 }); | |
163 }); | |
164 } | |
165 | |
166 | 151 |
| 152 void testOpenEmptyRequest() { |
| 153 var client = new HttpClient(); |
| 154 var methods = [ |
| 155 [client.get, 'GET'], |
| 156 [client.post, 'POST'], |
| 157 [client.put, 'PUT'], |
| 158 [client.delete, 'DELETE'], |
| 159 [client.patch, 'PATCH'], |
| 160 [client.head, 'HEAD']]; |
| 161 |
| 162 for (var method in methods) { |
| 163 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 164 server.listen((request) { |
| 165 Expect.equals(method[1], request.method); |
| 166 request.pipe(request.response); |
| 167 }); |
| 168 |
| 169 method[0]("127.0.0.1", server.port, "/") |
| 170 .then((request) => request.close()) |
| 171 .then((response) { |
| 172 response.listen((data) {}, onDone: server.close); |
| 173 }); |
| 174 }); |
| 175 } |
| 176 } |
| 177 |
| 178 |
| 179 void testOpenUrlEmptyRequest() { |
| 180 var client = new HttpClient(); |
| 181 var methods = [ |
| 182 [client.getUrl, 'GET'], |
| 183 [client.postUrl, 'POST'], |
| 184 [client.putUrl, 'PUT'], |
| 185 [client.deleteUrl, 'DELETE'], |
| 186 [client.patchUrl, 'PATCH'], |
| 187 [client.headUrl, 'HEAD']]; |
| 188 |
| 189 for (var method in methods) { |
| 190 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 191 server.listen((request) { |
| 192 Expect.equals(method[1], request.method); |
| 193 request.pipe(request.response); |
| 194 }); |
| 195 |
| 196 method[0](Uri.parse("http://127.0.0.1:${server.port}/")) |
| 197 .then((request) => request.close()) |
| 198 .then((response) { |
| 199 response.listen((data) {}, onDone: server.close); |
| 200 }); |
| 201 }); |
| 202 } |
| 203 } |
| 204 |
| 205 |
167 void testNoBuffer() { | 206 void testNoBuffer() { |
168 asyncStart(); | 207 asyncStart(); |
169 HttpServer.bind("127.0.0.1", 0).then((server) { | 208 HttpServer.bind("127.0.0.1", 0).then((server) { |
170 var response; | 209 var response; |
171 server.listen((request) { | 210 server.listen((request) { |
172 response = request.response; | 211 response = request.response; |
173 response.bufferOutput = false; | 212 response.bufferOutput = false; |
174 response.writeln('init'); | 213 response.writeln('init'); |
175 }); | 214 }); |
176 | 215 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 250 |
212 | 251 |
213 void main() { | 252 void main() { |
214 testGetEmptyRequest(); | 253 testGetEmptyRequest(); |
215 testGetDataRequest(); | 254 testGetDataRequest(); |
216 testGetInvalidHost(); | 255 testGetInvalidHost(); |
217 testGetServerClose(); | 256 testGetServerClose(); |
218 testGetServerCloseNoKeepAlive(); | 257 testGetServerCloseNoKeepAlive(); |
219 testGetServerForceClose(); | 258 testGetServerForceClose(); |
220 testGetDataServerForceClose(); | 259 testGetDataServerForceClose(); |
221 testPostEmptyRequest(); | 260 testOpenEmptyRequest(); |
| 261 testOpenUrlEmptyRequest(); |
222 testNoBuffer(); | 262 testNoBuffer(); |
223 } | 263 } |
OLD | NEW |