pub_server 0.1.5

  • Example
  • Installing
  • Versions
  • 71

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.


  • Differentiate between client- and server-side upload issues.


  • Drop support for Dart 1.x.


  • Support Dart 2 stable releases.

  • Support latest release of package:pub_semver.


  • Dart 2 support with dart2_constant.


  • 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');

Use this package as a library

1. Depend on it

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

  pub_server: ^0.1.5

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 flutter 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.5 Aug 28, 2018 Go to the documentation of pub_server 0.1.5 Download pub_server 0.1.5 archive
0.1.4+2 Aug 9, 2018 Go to the documentation of pub_server 0.1.4+2 Download pub_server 0.1.4+2 archive
0.1.4+1 Jul 24, 2018 Go to the documentation of pub_server 0.1.4+1 Download pub_server 0.1.4+1 archive
0.1.4 May 28, 2018 Go to the documentation of pub_server 0.1.4 Download pub_server 0.1.4 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

All 12 versions...

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

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

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: Flutter, other

Platform components identified in package: isolate.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
dart2_constant ^1.0.1 1.0.2+dart2
http_parser ^3.0.0 3.1.3
logging >=0.9.3 <1.0.0 0.11.3+2
mime >=0.9.3 <0.10.0 0.9.6+2
pub_semver ^1.1.0 1.4.2
shelf >=0.5.6 <0.8.0 0.7.3+3
yaml ^2.1.2 2.1.15
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
meta 1.1.6
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
string_scanner 1.0.4
typed_data 1.1.6
Dev dependencies
archive >=1.0.0 <3.0.0
args ^1.4.0
http ^0.11.0
path ^1.5.1 1.6.2
test ^1.3.0