dio_http2_adapter 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

Http2Adapter Pub

A Dio HttpClientAdapter which implements Http/2.0 .

Getting Started #

Install #

dependencies:
  dio_http2_adapter: x.x.x  #latest version

Usage #

import 'package:dio/dio.dart';
import 'package:dio_http2_adapter/http2.dart'; 

main() async {
  var dio = Dio()
    ..options.baseUrl = "https://www.ustc.edu.cn/"
    ..httpClientAdapter = Http2Adapter();

  Response<String> response;
  response = await dio.get("/?xx=6");
  print(response.data);
  response = await dio.get("2062/list.htm");
  print(response.data);
}

ConnectionManager #

ConnectionManager is used to manager the connections that should be reusable. The main responsibility of ConnectionManager is to implement a connection reuse strategy for http2.

dio.httpClientAdapter = Http2Adapter(
  ConnectionManager(
    idleTimeout: 10000,
    /// Ignore bad certificate
    onClientCreate: (_, clientSetting) => clientSetting.onBadCertificate = (_) => true,
  ),
);
  • idleTimeout: Sets the idle timeout(milliseconds) of non-active persistent connections. For the sake of socket reuse feature with http/2, the value should not be less than 1000 (1s).
  • onClientCreate:Callback when socket created. We can set trusted certificates and handler for unverifiable certificates.

You can also custom a connection manager with a specific connection reuse strategy by implementing the ConnectionManager.

[1.0.0] - 2019.9.18

  • Support redirect

[0.0.2] - 2019.9.17

  • A Dio HttpAdapter which support Http/2.0.

example/example.dart

import 'package:dio/dio.dart';
import 'package:dio_http2_adapter/dio_http2_adapter.dart';

main() async {
  var dio = Dio()
    ..options.baseUrl = "https://google.com"
    ..interceptors.add(LogInterceptor())
    ..httpClientAdapter = Http2Adapter(
      ConnectionManager(
        idleTimeout: 10000,
        // Ignore bad certificate
        onClientCreate: (_, config) => config.onBadCertificate = (_) => true,
      ),
    );

  Response<String> response;

  response = await dio.get("/?xx=6");
  print(response.data.length);
  print(response.redirects.length);
  print(response.data);
}

Use this package as a library

1. Depend on it

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


dependencies:
  dio_http2_adapter: ^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:dio_http2_adapter/dio_http2_adapter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >2.4.0 <3.0.0
dio ^3.0.0 3.0.3
http2 ^1.0.0 1.0.0
Transitive dependencies
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic 1.1.0
test ^1.5.1
test_coverage ^0.2.0