http2 1.0.0

  • Installing
  • Versions
  • 84

HTTP/2 for Dart

This library provides an http/2 interface on top of a bidirectional stream of bytes.


Here is a minimal example of connecting to a http/2 capable server, requesting a resource and iterating over the response.

import 'dart:convert';
import 'dart:io';

import 'package:http2/http2.dart';

main() async {
  var uri = Uri.parse('');

  var transport = new ClientTransportConnection.viaSocket(
    await SecureSocket.connect(,
      supportedProtocols: ['h2'],

  var stream = transport.makeRequest(
      new Header.ascii(':method', 'GET'),
      new Header.ascii(':path', uri.path),
      new Header.ascii(':scheme', uri.scheme),
      new Header.ascii(':authority',,
    endStream: true,

  await for (var message in stream.incomingMessages) {
    if (message is HeadersStreamMessage) {
      for (var header in message.headers) {
        var name = utf8.decode(;
        var value = utf8.decode(header.value);
        print('Header: $name: $value');
    } else if (message is DataStreamMessage) {
      // Use [message.bytes] (but respect 'content-encoding' header)
  await transport.finish();

An example with better error handling is available here.

See the API docs for more details.

Features and bugs

Please file feature requests and bugs at the issue tracker.


  • Graduate package to 1.0.
  • package:http2/http2.dart now reexports package:http2/transport.dart.


  • Discard messages incoming after stream cancellation.


  • On connection termination, try to dispatch existing messages, thereby avoiding terminating existing streams.

  • Fix ClientTransportConnection.isOpen to return false if we have exhausted the number of max-concurrent-streams.


  • Switch all uppercase constants from dart:convert to lowercase.


  • More changes required for making tests pass under Dart 2.0 runtime.
  • Modify sdk constraint to require '>=2.0.0-dev.40.0'.


  • Fixes for Dart 2.0.


  • Strong mode fixes and other cleanup.


  • Removed use of new Function syntax, since it isn't fully supported in Dart 1.24.


  • Added an onActiveStateChanged callback to Connection, which is invoked when the connection changes state from idle to active or from active to idle. This can be used to implement an idle connection timeout.


  • Fixed a bug where a closed window would not open correctly due to an increase in initial window size.


  • The endStream bit is now set on the requested frame, instead of on an empty data frame following it.
  • Added an onTerminated hook that is called when a TransportStream receives a RST_STREAM frame.


  • Add errorCode to exception toString message.


  • Fixing a performance issue in case the underlying socket is not writeable
  • Allow clients of MultiProtocolHttpServer to supply [http.ServerSettings]
  • Allow the draft version 'h2-14' in the ALPN protocol negogiation.


  • Adding support for MultiProtocolHttpServer in the package:http2/multiprotocol_server.dart library


  • First version of a HTTP/2 transport implementation in the package:http2/transport.dart library


  • Initial version

Use this package as a library

1. Depend on it

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

  http2: ^1.0.0

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:http2/http2.dart';
Version Uploaded Documentation Archive
1.0.0 Dec 14, 2018 Go to the documentation of http2 1.0.0 Download http2 1.0.0 archive
0.1.9 Nov 1, 2018 Go to the documentation of http2 0.1.9 Download http2 0.1.9 archive
0.1.8+2 Jul 16, 2018 Go to the documentation of http2 0.1.8+2 Download http2 0.1.8+2 archive
0.1.8+1 Jul 12, 2018 Go to the documentation of http2 0.1.8+1 Download http2 0.1.8+1 archive
0.1.8 Mar 21, 2018 Go to the documentation of http2 0.1.8 Download http2 0.1.8 archive
0.1.7 Jan 11, 2018 Go to the documentation of http2 0.1.7 Download http2 0.1.7 archive
0.1.6 Nov 3, 2017 Go to the documentation of http2 0.1.6 Download http2 0.1.6 archive
0.1.5 Oct 5, 2017 Go to the documentation of http2 0.1.5 Download http2 0.1.5 archive
0.1.4 Oct 2, 2017 Go to the documentation of http2 0.1.4 Download http2 0.1.4 archive
0.1.3 Jul 18, 2017 Go to the documentation of http2 0.1.3 Download http2 0.1.3 archive

All 15 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 14, 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

Primary library: package:http2/http2.dart with components: io.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use http2.dart. Packages with multiple examples should use example/


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.56.0 <3.0.0
Dev dependencies
mockito ^4.0.0
test ^1.2.0