HttpServer两次处理相同的请求吗?

时间:2013-11-07 20:31:05

标签: dart

尝试设置一个简单的飞镖HttpServer

import 'dart:io';

void main() {
  HttpServer.bind(InternetAddress.ANY_IP_V4, 80).then((server) {
    server.listen((HttpRequest request) {
      request.response.write('Hello, world.');
      request.response.close();
      print(new DateTime.now());
      print(request.connectionInfo.remoteAddress);
      print(request.method);
      print(request.headers.toString());
      print("--------------");      
    });
  });

  print("listing....");

}

从浏览器(Chrome)访问localhost时,似乎传入的请求已经两次处理

listing....
2013-11-07 15:19:24.478
InternetAddress('127.0.0.1', IP_V4)
GET
host: localhost:80
connection: keep-alive
cache-control: max-age=0
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
accept-encoding: gzip,deflate,sdch
accept-language: en-US,en;q=0.8
--------------
2013-11-07 15:19:24.554
InternetAddress('127.0.0.1', IP_V4)
GET
host: localhost:80
connection: keep-alive
accept: */*
user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
accept-encoding: gzip,deflate,sdch
accept-language: en-US,en;q=0.8
--------------

accept标头外,这两个请求看起来几乎完全相同。看起来浏览器没有两次启动请求:

enter image description here

那么,为什么请求会被处理两次?

编辑:Dart SDK版本0.8.10.6_r30036

1 个答案:

答案 0 :(得分:4)

您没有输出请求的内容(请求实例的url成员),这是两个请求之间的差异。

第一个请求请求您尝试打开的文件,可能是/。第二个请求由浏览器在内部发出,并请求favicon.ico在地址栏/标签标题中显示图标。