Skip to main content

basic_http_interceptor 0.2.1 copy "basic_http_interceptor: ^0.2.1" to clipboard
basic_http_interceptor: ^0.2.1 copied to clipboard

Pluggable HTTP interceptors for logging, headers, timeouts, hooks, and proxies, plus dynamic routing, RFC 7234 URL file caching, and LRU disk quota utilities.

example/basic_http_interceptor_example.dart

import 'package:logging/logging.dart';

import 'package:basic_http_interceptor/basic_http_interceptor.dart';

void main() {
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((record) {
    print(
        '${record.time}: [${record.level}] [${record.loggerName}] ${record.message}');
  });

  final logger = Logger('main');
  final jwt = '';
  final requestHeader = {
    'Authorization': 'Bearer $jwt',
  };

  final List<InterceptorContract> interceptors = [
    // logBody = true, or exist header X-Debug-Body, output body
    InterceptorLogger(logger, true),
    InterceptorHeader(requestHeader: requestHeader),
  ];

  final proxy = {
    'no_proxy': 'localhost,127.0.0.1,::1',
    'https_proxy': 'https://127.0.0.1:7890/',
    'http_proxy': 'http://127.0.0.1:7890/',
    'all_proxy': 'socks5://127.0.0.1:7891/',
  };

  final interClient = interceptedClient(
    interceptors: interceptors,
    proxy: proxy,
  );

  // https://www.google.com/search?q=hello+world
  final url = buildUrlString(
    'https://www.google.com',
    {'q': 'hello world'},
  );

  // http://localhost:8000/testdb
  //final url = buildUrlString('http://localhost:8000/testdb', null);

  final uri = Uri.parse(url);
  interClient.get(uri).then((response) {
    logger.info('--- response ---');
    logger.info(response.request?.method);
    logger.info(response.request?.url.toString());
    logger.info(response.statusCode);
    // logger.info(response.headers.toString());
    // logger.info(response.body.toString());
  });
}
0
likes
150
points
1.18k
downloads

Documentation

API reference

Publisher

verified publisheriche2.com

Weekly Downloads

Pluggable HTTP interceptors for logging, headers, timeouts, hooks, and proxies, plus dynamic routing, RFC 7234 URL file caching, and LRU disk quota utilities.

Repository (GitHub)
View/report issues

Topics

#http #network #interceptor #cache #proxy

Funding

Consider supporting this project:

github.com
buymeacoffee.com

License

MIT (license)

Dependencies

http, http_interceptor, logging

More

Packages that depend on basic_http_interceptor