Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does HttpServer handle the same request twice?

Tags:

dart

Trying to set up a simple 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....");

}

When hitting localhost from a browser (Chrome), it appears as if the incoming request is handled twice:

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
--------------

Those two requests look almost identical, except for the accept header. Doesn't look like the browser is firing up the request twice:

enter image description here

So, why does the request get handled twice?

EDIT: Dart SDK version 0.8.10.6_r30036

like image 344
Max Avatar asked Nov 18 '25 11:11

Max


1 Answers

You don't output what is requested (the url member of the request instance) and that is the difference between the two requests.

The first request requests the file you try to open, probably /. The second request is issued internally by the browser and requests favicon.ico to display the icon in the address bar / tab title.

like image 162
Fox32 Avatar answered Nov 21 '25 08:11

Fox32



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!