http2 1.0.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 80

HTTP/2 for Dart #

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

Usage: #

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('https://www.google.com/');

  var transport = new ClientTransportConnection.viaSocket(
    await SecureSocket.connect(
      uri.host,
      uri.port,
      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', uri.host),
    ],
    endStream: true,
  );

  await for (var message in stream.incomingMessages) {
    if (message is HeadersStreamMessage) {
      for (var header in message.headers) {
        var name = utf8.decode(header.name);
        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.

1.0 #

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

0.1.9 #

  • Discard messages incoming after stream cancellation.

0.1.8+2 #

  • 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.

0.1.8+1 #

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

0.1.8 #

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

0.1.7 #

  • Fixes for Dart 2.0.

0.1.6 #

  • Strong mode fixes and other cleanup.

0.1.5 #

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

0.1.4 #

  • 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.

0.1.3 #

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

0.1.2 #

  • 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.

0.1.1+2 #

  • Add errorCode to exception toString message.

0.1.1+1 #

  • 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.

0.1.1 #

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

0.1.0 #

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

0.0.1 #

  • Initial version

Use this package as a library

1. Depend on it

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


dependencies:
  http2: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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...

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

We analyzed this package on Jun 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms: Flutter, other

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

Health suggestions

Fix lib/src/flowcontrol/stream_queues.dart. (-2.96 points)

Analysis of lib/src/flowcontrol/stream_queues.dart reported 6 hints, including:

line 82 col 11: Use isNotEmpty instead of length

line 100 col 12: Use isNotEmpty instead of length

line 108 col 35: Use isEmpty instead of length

line 271 col 13: Use isNotEmpty instead of length

line 302 col 17: Use isNotEmpty instead of length

Fix lib/src/connection.dart. (-2.48 points)

Analysis of lib/src/connection.dart reported 5 hints:

line 68 col 13: Use isEmpty instead of length

line 143 col 31: Use = to separate a named parameter from its default value.

line 368 col 31: Use = to separate a named parameter from its default value.

line 406 col 35: Use = to separate a named parameter from its default value.

line 459 col 22: Use = to separate a named parameter from its default value.

Fix lib/src/frames/frame_writer.dart. (-2.48 points)

Analysis of lib/src/frames/frame_writer.dart reported 5 hints:

line 34 col 68: Use = to separate a named parameter from its default value.

line 60 col 22: Use = to separate a named parameter from its default value.

line 115 col 22: Use = to separate a named parameter from its default value.

line 224 col 48: Use = to separate a named parameter from its default value.

line 256 col 58: Use = to separate a named parameter from its default value.

Fix additional 12 files with analysis or formatting issues. (-15.92 points)

Additional issues in the following files:

  • lib/src/streams/stream_handler.dart (5 hints)
  • lib/transport.dart (5 hints)
  • lib/src/flowcontrol/connection_queues.dart (4 hints)
  • lib/src/hpack/hpack.dart (4 hints)
  • lib/src/settings/settings.dart (4 hints)
  • lib/src/testing/debug.dart (4 hints)
  • lib/multiprotocol_server.dart (1 hint)
  • lib/src/connection_preface.dart (1 hint)
  • lib/src/flowcontrol/window.dart (1 hint)
  • lib/src/frames/frame_reader.dart (1 hint)
  • lib/src/hpack/huffman.dart (1 hint)
  • lib/src/testing/client.dart (1 hint)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and http2.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

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