Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: pkg/http/test/client_test.dart

Issue 12084052: Always treat headers as individual strings in pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 library client_test; 5 library client_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 import 'package:http/http.dart' as http; 11 import 'package:http/http.dart' as http;
12 import 'package:http/src/utils.dart'; 12 import 'package:http/src/utils.dart';
13 import 'utils.dart'; 13 import 'utils.dart';
14 14
15 void main() { 15 void main() {
16 setUp(startServer); 16 setUp(startServer);
17 tearDown(stopServer); 17 tearDown(stopServer);
18 18
19 test('#send a StreamedRequest', () { 19 test('#send a StreamedRequest', () {
20 var client = new http.Client(); 20 var client = new http.Client();
21 var request = new http.StreamedRequest("POST", serverUrl); 21 var request = new http.StreamedRequest("POST", serverUrl);
22 request.headers[HttpHeaders.CONTENT_TYPE] = 22 request.headers[HttpHeaders.CONTENT_TYPE] =
23 'application/json; charset=utf-8'; 23 'application/json; charset=utf-8';
24 24
25 expect(client.send(request).then((response) { 25 expect(client.send(request).then((response) {
26 expect(response.request, equals(request)); 26 expect(response.request, equals(request));
27 expect(response.statusCode, equals(200)); 27 expect(response.statusCode, equals(200));
28 expect(response.headers['single'], equals('value'));
29 // dart:io internally normalizes outgoing headers so that they never have
30 // multiple headers with the same name, so there's no way to test whether
31 // we handle that case correctly.
32
28 return response.stream.bytesToString(); 33 return response.stream.bytesToString();
29 }).whenComplete(client.close), completion(parse(equals({ 34 }).whenComplete(client.close), completion(parse(equals({
30 'method': 'POST', 35 'method': 'POST',
31 'path': '/', 36 'path': '/',
32 'headers': { 37 'headers': {
33 'content-type': ['application/json; charset=utf-8'], 38 'content-type': ['application/json; charset=utf-8'],
34 'transfer-encoding': ['chunked'] 39 'transfer-encoding': ['chunked']
35 }, 40 },
36 'body': '{"hello": "world"}' 41 'body': '{"hello": "world"}'
37 })))); 42 }))));
38 43
39 request.sink.add('{"hello": "world"}'.charCodes); 44 request.sink.add('{"hello": "world"}'.charCodes);
40 request.sink.close(); 45 request.sink.close();
41 }); 46 });
42 47
43 test('#send with an invalid URL', () { 48 test('#send with an invalid URL', () {
44 var client = new http.Client(); 49 var client = new http.Client();
45 var url = Uri.parse('http://http.invalid'); 50 var url = Uri.parse('http://http.invalid');
46 var request = new http.StreamedRequest("POST", url); 51 var request = new http.StreamedRequest("POST", url);
47 request.headers[HttpHeaders.CONTENT_TYPE] = 52 request.headers[HttpHeaders.CONTENT_TYPE] =
48 'application/json; charset=utf-8'; 53 'application/json; charset=utf-8';
49 54
50 expect(client.send(request), throwsSocketIOException); 55 expect(client.send(request), throwsSocketIOException);
51 56
52 request.sink.add('{"hello": "world"}'.charCodes); 57 request.sink.add('{"hello": "world"}'.charCodes);
53 request.sink.close(); 58 request.sink.close();
54 }); 59 });
55 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698