-
Notifications
You must be signed in to change notification settings - Fork 393
Closed
Description
A simple request like getting the string "hello" using the http package from a shelf server running on the same host takes an unusually long time (5 seconds) when the url refers to localhost on my mac. The same connection takes less than 5 milliseconds on Chrome. The request takes less than 100 ms when the url uses 127.0.0.1 instead of localhost. I repeated the test on an Ubuntu Linux machine using localhost and it behaves as expected.
client
import 'package:http/http.dart' as http;
main(List<String> args) async {
var client = new http.Client();
Stopwatch sw = new Stopwatch();
sw.start();
var response = await client.get(Uri.parse("http://localhost:10080"));
sw.stop();
print('response received ${sw.elapsedMilliseconds}');
client.close();
}
server
import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
main(List<String> args) async {
var handler = (Request r){
return new Response.ok("hello");
} ;
var server = await serve(const Pipeline()
.addMiddleware(logRequests())
.addHandler(handler), InternetAddress.ANY_IP_V4, 10080);
print('Serving at http://${server.address.host}:${server.port}');
sdk: 1.19.1
mac os x: 10.11.6
http: 0.11.3+9
shelf: 0.6.5+3
Metadata
Metadata
Assignees
Labels
No labels