Skip to content

Files

Latest commit

d7b0b7f · Jan 29, 2025

History

History

http2_adapter

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 24, 2025
May 11, 2024
Jan 24, 2025
Jan 24, 2025
Mar 19, 2024
Sep 17, 2019
Jan 29, 2025
Dec 18, 2022
Oct 1, 2023
Mar 10, 2023
Jul 3, 2024
Oct 1, 2023
Jan 29, 2025

dio_http2_adapter

Pub

An adapter that combines HTTP/2 and dio. Supports reusing connections, header compression, etc.

Getting Started

Install

Add the dio_http2_adapter package to your pubspec dependencies.

Usage

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

void main() async {
  final dio = Dio()
    ..options.baseUrl = 'https://pub.dev'
    ..interceptors.add(LogInterceptor())
    ..httpClientAdapter = Http2Adapter(
      ConnectionManager(idleTimeout: Duration(seconds: 10)),
    );

  Response<String> response;
  response = await dio.get('/?xx=6');
  for (final e in response.redirects) {
    print('redirect: ${e.statusCode} ${e.location}');
  }
  print(response.data);
}

Ignoring a bad certificate

void main() async {
  final dio = Dio()
    ..options.baseUrl = 'https://pub.dev'
    ..interceptors.add(LogInterceptor())
    ..httpClientAdapter = Http2Adapter(
      ConnectionManager(
        idleTimeout: Duration(seconds: 10),
        onClientCreate: (_, config) => config.onBadCertificate = (_) => true,
      ),
    );
}

Configuring the proxy

void main() async {
  final dio = Dio()
    ..options.baseUrl = 'https://pub.dev'
    ..interceptors.add(LogInterceptor())
    ..httpClientAdapter = Http2Adapter(
      ConnectionManager(
        idleTimeout: Duration(seconds: 10),
        onClientCreate: (_, config) =>
            config.proxy = Uri.parse('http://login:password@192.168.0.1:8888'),
      ),
    );
}