b2a13038b2
BUG=8049 Review URL: https://codereview.chromium.org//12084052 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17819 260f80e4-7a28-3924-810f-c04153c831b5
61 lines
1.9 KiB
Dart
61 lines
1.9 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library client_test;
|
|
|
|
import 'dart:io';
|
|
import 'dart:uri';
|
|
|
|
import 'package:unittest/unittest.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/src/utils.dart';
|
|
import 'utils.dart';
|
|
|
|
void main() {
|
|
setUp(startServer);
|
|
tearDown(stopServer);
|
|
|
|
test('#send a StreamedRequest', () {
|
|
var client = new http.Client();
|
|
var request = new http.StreamedRequest("POST", serverUrl);
|
|
request.headers[HttpHeaders.CONTENT_TYPE] =
|
|
'application/json; charset=utf-8';
|
|
|
|
expect(client.send(request).then((response) {
|
|
expect(response.request, equals(request));
|
|
expect(response.statusCode, equals(200));
|
|
expect(response.headers['single'], equals('value'));
|
|
// dart:io internally normalizes outgoing headers so that they never have
|
|
// multiple headers with the same name, so there's no way to test whether
|
|
// we handle that case correctly.
|
|
|
|
return response.stream.bytesToString();
|
|
}).whenComplete(client.close), completion(parse(equals({
|
|
'method': 'POST',
|
|
'path': '/',
|
|
'headers': {
|
|
'content-type': ['application/json; charset=utf-8'],
|
|
'transfer-encoding': ['chunked']
|
|
},
|
|
'body': '{"hello": "world"}'
|
|
}))));
|
|
|
|
request.sink.add('{"hello": "world"}'.charCodes);
|
|
request.sink.close();
|
|
});
|
|
|
|
test('#send with an invalid URL', () {
|
|
var client = new http.Client();
|
|
var url = Uri.parse('http://http.invalid');
|
|
var request = new http.StreamedRequest("POST", url);
|
|
request.headers[HttpHeaders.CONTENT_TYPE] =
|
|
'application/json; charset=utf-8';
|
|
|
|
expect(client.send(request), throwsSocketIOException);
|
|
|
|
request.sink.add('{"hello": "world"}'.charCodes);
|
|
request.sink.close();
|
|
});
|
|
}
|