Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an echo server for testing #35

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ dependencies:
path: ">=0.9.0 <2.0.0"
stack_trace: ">=0.9.1 <2.0.0"
dev_dependencies:
unittest: ">=0.9.0 <0.12.0"
test: ">=0.12.0 <0.13.0"
environment:
sdk: ">=1.9.0 <2.0.0"
29 changes: 29 additions & 0 deletions test/echo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2015, 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.

import 'dart:io'
show
HttpServer,
HttpRequest,
ServerSocket,
SecurityContext,
InternetAddress;

import 'utils.dart' show echoPort;

/// Simple HTTP server that listens for requests and echoes the request body
/// in the response. It is used for testing the http package.
main() async {
final httpServer = await HttpServer.bind(InternetAddress.ANY_IP_V6, echoPort);
print('Echo server listening on port ${httpServer.port} (http)');
_serve(httpServer);
}

_serve(HttpServer httpServer) async {
await for (HttpRequest request in httpServer) {
final response = request.response;
response.headers.add('Access-Control-Allow-Origin', '*');
request.pipe(response);
}
}
3 changes: 2 additions & 1 deletion test/html/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// 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.

@TestOn("browser")
import 'package:http/http.dart' as http;
import 'package:http/browser_client.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
3 changes: 2 additions & 1 deletion test/html/streamed_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// 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.

@TestOn("browser")
import 'package:http/http.dart' as http;
import 'package:http/browser_client.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
10 changes: 7 additions & 3 deletions test/html/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

import 'dart:html';

import '../utils.dart' show echoPort;
export '../utils.dart';

/// The test server's echo URL.
Uri get echoUrl => Uri.parse(
'${window.location.protocol}//${window.location.host}/echo');
/// The echo server's URL.
Uri get echoUrl {
var protocol = 'http';
var host = window.location.host.split(':')[0];
return Uri.parse('$protocol://$host:$echoPort');
}
3 changes: 2 additions & 1 deletion test/io/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// 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.

@TestOn("vm")
import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
3 changes: 2 additions & 1 deletion test/io/http_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// 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.

@TestOn("vm")
import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
3 changes: 2 additions & 1 deletion test/io/multipart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// 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.

@TestOn("vm")
import 'dart:async';
import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:path/path.dart' as path;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
3 changes: 2 additions & 1 deletion test/io/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// 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.

@TestOn("vm")
import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
3 changes: 2 additions & 1 deletion test/io/streamed_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// 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.

@TestOn("vm")
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/io/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:io';

import 'package:http/http.dart';
import 'package:http/src/utils.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

export '../utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/mock_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:http/src/utils.dart';
import 'package:http/testing.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/multipart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:async';

import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
2 changes: 1 addition & 1 deletion test/response_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:async';

import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

void main() {
group('()', () {
Expand Down
2 changes: 1 addition & 1 deletion test/streamed_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'utils.dart';

Expand Down
5 changes: 4 additions & 1 deletion test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

/// Port for an Echo http server
const echoPort = 8395;

/// A dummy URL for constructing requests that won't be sent.
Uri get dummyUrl => Uri.parse('http://dartlang.org/');
Expand Down