request_extras 1.0.0 icon indicating copy to clipboard operation
request_extras: ^1.0.0 copied to clipboard

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

request_extras. #

Request extras is a simple library that contains extension methods for dealing Dart HttpRequest objects.

For now the library mainly focuses on simplifying the usage of getters and setters on headers property by transforming HttpHeaders.value and HttpHeaders.set calls into getters and setter that exist directly on the HttpRequest object. All staticly typed, and without having to specify the names of unsupported headers as strings!

In total, there are 10 different extension exported, each extension deals with a different header type that correspond to Http headers as documented on MDN.


Usage #

A simple usage example:

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';

Features and bugs #

Please file feature requests and bugs at the issue tracker.

pub points


verified publisher

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


API reference


Icon for licenses.MIT (LICENSE.txt)


Packages that depend on request_extras