anchor.diff:          response.close();
           return;
         }
  -
   
         file.length().then((length) {
           // Always set Accept-Ranges and Last-Modified headers.
  
positive.code: import 'package:path/path.dart';
  
  class StaticFileHandler {
  
    HttpServer _server;
    Builder _root;
    int _port;
    String _ip;
    int _maxAge;
  
    int get port => _port;
    String get documentRoot => _root.root;
    String get ip => _ip;
    int get maxAge => _maxAge;
        set maxAge(num value) => _maxAge = (value >= 0) ? value : 0;
  
    final _extToContentType = {
      "bz"      : "application/x-bzip",
      "bz2"     : "application/x-bzip2",
      "dart"    : "application/dart",
      "exe"     : "application/octet-stream",
      "gif"     : "image/gif",
      "gz"      : "application/x-gzip",
      "html"    : "text/html; charset=utf-8",  // Assumes UTF-8 files.
      "jpg"     : "image/jpeg",
      "js"      : "application/javascript",
      "json"    : "application/json",
      "mp3"     : "audio/mpeg",
      "mp4"     : "video/mp4",
      "pdf"     : "application/pdf",
      "png"     : "image/png",
      "tar.gz"  : "application/x-tar",
      "tgz"     : "application/x-tar",
      "txt"     : "text/plain; charset=utf-8",  // Assumes UTF-8 files.
      "webp"    : "image/webp",
      "webm"    : "video/webm",
      "zip"     : "application/zip"
    };
  
    /**
     * Default constructor.
     */
    StaticFileHandler(String documentRoot, {int port: 80, String ip: '0.0.0.0'}) {
      // If port == 0 the OS will pick a random available port for us
      if (65535 < port || 0 > port ) {
        print("Invalid port");
        exit(-1);
      }
  
      _port = port;
  
      _root = new Builder(root: absolute(normalize(documentRoot)));
  
      // @todo: check that the IP is valid
      _ip = ip;
  
      _checkDir();
    }
  
    /**
     * Only sets the directory to be used as document root.
     */
    StaticFileHandler.serveFolder(String directory) {
      _root = new Builder(root:  absolute(normalize(directory)));
      _checkDir();
    }
  
    void _errorHandler(error) {
      // Every error goes here. Add potential logger here.
      print("Error: ${error.toString()}");
    }
  
    void _checkDir() {
      var dir = new Directory(_root.root);
      if (!dir.existsSync()) {
        print("Root path does not exist or is not a directory");
        exit(-1);
      }
    }
  
    /**
     * Serve the directory [dir] to the [request]. The content of the directory
     * will be listed in bullet-form, with a link to each element.
     */
    void _serveDir(Directory dir, HttpRequest request) {
      HttpResponse response = request.response;
  
      response.write("<html><head>");
      response.write("<title>${request.uri}</title>");
      response.write("</head><body>");
      response.write("<h1>Contents of ${request.uri}</h1><ul>");
  
      dir.list().listen(
          (entity) {
            String name = basename(entity.path);
            Builder hrefBuilder = new Builder(root: request.uri.path);
            String href = hrefBuilder.join(name);
            //Path href = new Path(request.uri.path).append(name);
            response.write("<li><a href='$href'>$name</a></li>");
          },
          onDone: () {
            response.write("</ul></body></html>");
            response.close();
          },
          onError: _errorHandler);
    }
  
    /**
  
negative.code:           response.headers.set(HttpHeaders.CONTENT_LENGTH, length);
          }
  
          // Fall back to sending the entire content.
          pipeToResponse(file.openRead(), response);
        }, onError: fileError);
      }, onError: fileError);
    }
  
    /**
     * Seeks for file at documentRoot/relativePath and depending on [request]
     * parameters it fills [request.response].
     */
    void handleRequest(String relativePath, HttpRequest request) {
      request.response.done.catchError(
          //TODO
        () => throw new StateError("Error creating response")
      );
  
      //TODO check format, consider using Builder
      String path = documentRoot + relativePath;
  
      FileSystemEntity.type(path)
      .then((type) {
  