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

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

Issue 16758008: Add 'Server' and 'User-Agent' default header fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: git cl dcommit Created 7 years, 6 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
« no previous file with comments | « no previous file | pkg/http/test/http_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
10 import 'package:http/src/utils.dart'; 10 import 'package:http/src/utils.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 import 'utils.dart'; 13 import 'utils.dart';
14 14
15 void main() { 15 void main() {
16 tearDown(stopServer); 16 tearDown(stopServer);
17 17
18 test('#send a StreamedRequest', () { 18 test('#send a StreamedRequest', () {
19 expect(startServer().then((_) { 19 expect(startServer().then((_) {
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 request.headers[HttpHeaders.USER_AGENT] = 'Dart';
24 25
25 expect(client.send(request).then((response) { 26 expect(client.send(request).then((response) {
26 expect(response.request, equals(request)); 27 expect(response.request, equals(request));
27 expect(response.statusCode, equals(200)); 28 expect(response.statusCode, equals(200));
28 expect(response.headers['single'], equals('value')); 29 expect(response.headers['single'], equals('value'));
29 // dart:io internally normalizes outgoing headers so that they never 30 // dart:io internally normalizes outgoing headers so that they never
30 // have multiple headers with the same name, so there's no way to test 31 // have multiple headers with the same name, so there's no way to test
31 // whether we handle that case correctly. 32 // whether we handle that case correctly.
32 33
33 return response.stream.bytesToString(); 34 return response.stream.bytesToString();
34 }).whenComplete(client.close), completion(parse(equals({ 35 }).whenComplete(client.close), completion(parse(equals({
35 'method': 'POST', 36 'method': 'POST',
36 'path': '/', 37 'path': '/',
37 'headers': { 38 'headers': {
38 'content-type': ['application/json; charset=utf-8'], 39 'content-type': ['application/json; charset=utf-8'],
39 'accept-encoding': ['gzip'], 40 'accept-encoding': ['gzip'],
41 'user-agent': ['Dart'],
40 'transfer-encoding': ['chunked'] 42 'transfer-encoding': ['chunked']
41 }, 43 },
42 'body': '{"hello": "world"}' 44 'body': '{"hello": "world"}'
43 })))); 45 }))));
44 46
45 request.sink.add('{"hello": "world"}'.codeUnits); 47 request.sink.add('{"hello": "world"}'.codeUnits);
46 request.sink.close(); 48 request.sink.close();
47 }), completes); 49 }), completes);
48 }); 50 });
49 51
50 test('#send with an invalid URL', () { 52 test('#send with an invalid URL', () {
51 expect(startServer().then((_) { 53 expect(startServer().then((_) {
52 var client = new http.Client(); 54 var client = new http.Client();
53 var url = Uri.parse('http://http.invalid'); 55 var url = Uri.parse('http://http.invalid');
54 var request = new http.StreamedRequest("POST", url); 56 var request = new http.StreamedRequest("POST", url);
55 request.headers[HttpHeaders.CONTENT_TYPE] = 57 request.headers[HttpHeaders.CONTENT_TYPE] =
56 'application/json; charset=utf-8'; 58 'application/json; charset=utf-8';
57 59
58 expect(client.send(request), throwsSocketIOException); 60 expect(client.send(request), throwsSocketIOException);
59 61
60 request.sink.add('{"hello": "world"}'.codeUnits); 62 request.sink.add('{"hello": "world"}'.codeUnits);
61 request.sink.close(); 63 request.sink.close();
62 }), completes); 64 }), completes);
63 }); 65 });
64 } 66 }
OLDNEW
« no previous file with comments | « no previous file | pkg/http/test/http_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698