request_extras 1.0.0

Dart native
Flutter Android iOS

Useful utility extension methods on the Dart Sdk HttpRequest class for getting and setting headers.

example/request_extras_example.dart

import 'dart:io';

/// Lets import some headers extensions.
import 'package:request_extras/request_extras.dart' show ProxyHeaders, SecurityHeaders;

main() {
  HttpRequest request;
  // Here's how you'd normally have to deal with HttpRequest headers using the Dart Sdk.
  /// Getting and setting a header not included in the SDK.
  const myHeaderName = 'X-Forwarded-For';
  final xForwardFor = request.headers.value(myHeaderName);
  request.headers.set(myHeaderName, 'some header value');

  /// Getting and setting a header that IS included in the Dart SDK.
  final host = request.headers.value(HttpHeaders.hostHeader);
  request.headers.set(HttpHeaders.hostHeader, 'some header value');

  /// This can be simplified by using request extras.
  final clientIp = request.xClientIpHeader;
  request.xClientIpHeader = 'Some Value';
  final corsPolicy = request.crossOriginOpenerPolicyHeader;
  request.crossOriginOpenerPolicyHeader = 'Some Cors Policy';
}
0
likes
85
pub points
0%
popularity

Publisher

techstar.dev

Useful utility extension methods on the Dart Sdk HttpRequest class for getting and setting headers.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE.txt)

More

Packages that depend on request_extras