pub_server 0.1.3

  • Example
  • Installing
  • Versions
  • 81

Provides re-usable code for making a Dart package repository server. The package:pub_server/shelf_pubserver.dart library provides a shelf HTTP handler which provides the HTTP API used by the pub client. One can use different backend implementations by implementing the PackageRepository interface of the package:pub_server/repository.dart library.

Example pub repository server

An experimental pub server based on a file system can be found in example/example.dart. It uses a filesystem-based PackageRepository for storing packages and has a read-only fallback to the real site, if a package is not available locally. This allows one to use all packages and have additional ones, on top of the publicly available packages, available only locally.

It can be run as follows

~ $ git clone
~ $ cd pub_server
~/pub_server $ pub get
~/pub_server $ dart example/example.dart -d /tmp/package-db
Listening on http://localhost:8080

To make the pub client use this repository configure your shell via:

    $ export PUB_HOSTED_URL=http://localhost:8080

Using it for uploading new packages to the locally running server or downloading packages locally available or via a fallback to is as easy as:

~/foobar $ export PUB_HOSTED_URL=http://localhost:8080
~/foobar $ pub get
~/foobar $ pub publish
Publishing x 0.1.0 to http://localhost:8080:
|-- ...
'-- pubspec.yaml

Looks great! Are you ready to upload your package (y/n)? y
Successfully uploaded package.

The fact that the pub publish command requires you to grant it oauth2 access - which requires a Google account - is due to the fact that the pub publish cannot work without authentication or with another authentication scheme. But the information sent by the pub client is not used for this local server at the moment.

NOTE: This is package is an alpha version and is not recommended for production use.


  • now has more specific return type: Future<Stream<List<int>>>.

  • Fix incorrect boundary parsing during upload.

  • Update minimum Dart SDK to 1.23.0.


  • Add support for generic exceptions raised e.g. due to pubspec.yaml validation failure.


  • Support the latest version of pkg/shelf.


  • Support the latest release of pub_semver.


  • Fixed null comparision.


  • Updated dependencies.


  • Return "400 Bad Request" in case the version number encoded in the URL is not a valid semantic version


Initial release.


// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:args/args.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:http/http.dart' as http;
import 'package:pub_server/shelf_pubserver.dart';

import 'src/examples/cow_repository.dart';
import 'src/examples/file_repository.dart';
import 'src/examples/http_proxy_repository.dart';

final Uri pubDartLangOrg = Uri.parse('');

main(List<String> args) {
  var parser = argsParser();
  var results = parser.parse(args);

  var directory = results['directory'] as String;
  var host = results['host'] as String;
  var port = int.parse(results['port'] as String);
  var standalone = results['standalone'] as bool;

  if ( > 0) {
    print('Got unexpected arguments: "${' ')}".\n\nUsage:\n');

  runPubServer(directory, host, port, standalone);

runPubServer(String baseDir, String host, int port, bool standalone) {
  var client = new http.Client();

  var local = new FileRepository(baseDir);
  var remote = new HttpProxyRepository(client, pubDartLangOrg);
  var cow = new CopyAndWriteRepository(local, remote, standalone);

  var server = new ShelfPubServer(cow);
  print('Listening on http://$host:$port\n'
      'To make the pub client use this repository configure your shell via:\n'
      '    \$ export PUB_HOSTED_URL=http://$host:$port\n'

  return shelf_io.serve(
      const Pipeline()

ArgParser argsParser() {
  var parser = new ArgParser();

      abbr: 'd', defaultsTo: 'pub_server-repository-data');

  parser.addOption('host', abbr: 'h', defaultsTo: 'localhost');

  parser.addOption('port', abbr: 'p', defaultsTo: '8080');
  parser.addFlag('standalone', abbr: 's', defaultsTo: false);
  return parser;

void setupLogger() {
  Logger.root.onRecord.listen((LogRecord record) {
    var head = '${record.time} ${record.level} ${record.loggerName}';
    var tail = record.stackTrace != null ? '\n${record.stackTrace}' : '';
    print('$head ${record.message} $tail');

1. Depend on it

Add this to your package's pubspec.yaml file:

  pub_server: "^0.1.3"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:pub_server/repository.dart';

import 'package:pub_server/shelf_pubserver.dart';
Version Uploaded Documentation Archive
0.1.3 Jan 4, 2018 Go to the documentation of pub_server 0.1.3 Download pub_server 0.1.3 archive
0.1.2 Oct 30, 2017 Go to the documentation of pub_server 0.1.2 Download pub_server 0.1.2 archive
0.1.1+4 Sep 6, 2017 Go to the documentation of pub_server 0.1.1+4 Download pub_server 0.1.1+4 archive
0.1.1+3 Sep 16, 2016 Go to the documentation of pub_server 0.1.1+3 Download pub_server 0.1.1+3 archive
0.1.1+2 Nov 9, 2015 Go to the documentation of pub_server 0.1.1+2 Download pub_server 0.1.1+2 archive
0.1.1+1 Oct 12, 2015 Go to the documentation of pub_server 0.1.1+1 Download pub_server 0.1.1+1 archive
0.1.1 Jul 10, 2015 Go to the documentation of pub_server 0.1.1 Download pub_server 0.1.1 archive
0.1.0 May 5, 2015 Go to the documentation of pub_server 0.1.0 Download pub_server 0.1.0 archive


We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6


Describes how popular the package is relative to other packages. [more]
63 / 100
Code health derived from static analysis. [more]
99 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, other

Platform components identified in package: isolate.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 6 hints.

    Strong-mode analysis of lib/shelf_pubserver.dart gave the following hint:

    line: 271 col: 22
    'JSON' is deprecated and shouldn't be used.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0
http_parser ^3.0.0 3.1.1
logging >=0.9.3 <1.0.0 0.11.3+1
mime >=0.9.3 <0.10.0 0.9.6
pub_semver >=1.1.0 <1.4.0 1.3.7
shelf >=0.5.6 <0.8.0 0.7.2
yaml >=2.1.2 <3.0.0 2.1.13
Transitive dependencies
async 2.0.6
charcode 1.1.1
collection 1.14.9
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.5
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
archive >=1.0.0 <2.0.0
args >=1.0.0 <2.0.0
http >0.11.0 <0.12.0
path ^1.5.1 1.5.1
test >=0.12.18+1 <0.13.0