OLD | NEW |
| (Empty) |
1 library http_base.http_base_io_test; | |
2 | |
3 import 'dart:async'; | |
4 import 'dart:io'; | |
5 import 'dart:convert'; | |
6 | |
7 import 'package:http_base/http_base_io.dart'; | |
8 import 'package:unittest/unittest.dart'; | |
9 | |
10 main() { | |
11 test('io-client', () { | |
12 HttpServer.bind('127.0.0.1', 0).then(expectAsync((HttpServer server) { | |
13 server.first.then(expectAsync((request) { | |
14 expect(request.method, equals('POST')); | |
15 expect(request.headers.value('foo'), equals('bar')); | |
16 | |
17 return request.fold([], (buf, data) => buf..addAll(data)).then((data) { | |
18 request | |
19 ..response.statusCode = 201 | |
20 ..response.headers.set('foo', ['foo', 'bar']) | |
21 ..response.add(data) | |
22 ..response.close(); | |
23 }); | |
24 })).whenComplete(() => server.close()); | |
25 | |
26 var client = new Client(); | |
27 var uri = Uri.parse('http://127.0.0.1:${server.port}/'); | |
28 var headers = new HeadersImpl({'foo' : 'bar'}); | |
29 var body = (new StreamController() | |
30 ..add(UTF8.encode('my-data')) | |
31 ..close()).stream; | |
32 | |
33 var request = new RequestImpl('POST', uri, headers: headers, body: body); | |
34 client(request).then(expectAsync((response) { | |
35 expect(response.statusCode, equals(201)); | |
36 // NOTE: dart:io joins multiple values with ", ". | |
37 expect(response.headers['foo'], equals('foo, bar')); | |
38 expect(response.headers.getMultiple('foo').toList(), | |
39 equals(['foo','bar'])); | |
40 | |
41 response.read() | |
42 .transform(UTF8.decoder).join('').then(expectAsync((data) { | |
43 expect(data, equals('my-data')); | |
44 })); | |
45 })); | |
46 })); | |
47 }); | |
48 } | |
OLD | NEW |