galileo_http_server library

Utilities for working with HttpServer.


Serving all files from the current directory.

import 'dart:io';

import 'package:http_server/http_server.dart';

Future<void> serveCurrentDirectory() async {
  var staticFiles = VirtualDirectory('.')..allowDirectoryListing = true;

  var server = await HttpServer.bind('', 7777);
  print('Server running');

Virtual directory

The VirtualDirectory class makes it easy to serve static content from the file system. It supports:

  • Range-based requests.
  • If-Modified-Since based caching.
  • Automatic GZip-compression of content.
  • Following symlinks, either throughout the system or inside a jailed root.
  • Directory listing.

See VirtualDirectory for more information.

Virtual host

The VirtualHost class helps to serve multiple hosts on the same address, by using the Host field of the incoming requests. It also works with wildcards for sub-domains.

var virtualHost = new VirtualHost(server);
// Filter out on a specific host
var stream1 = virtualServer.addHost('');
// Wildcard for any other sub-domains.
var stream2 = virtualServer.addHost('*');
// Requests not matching any hosts.
var stream3 = virtualServer.unhandled;

See VirtualHost for more information.


A HTTP content body produced by HttpBodyHandler for either HttpRequest or HttpClientResponse.
A wrapper around a file upload.
A handler for processing and collecting HTTP message data in to an HttpBody.
The body of a HttpClientResponse.
The data in a multipart/form-data part.
The body of a HttpRequest.
A VirtualDirectory can serve files and directory-listing from a root path, to HttpRequests.
A utility for handling multiple hosts on multiple sources using a named-based approach.