request_extras 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

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.

license.

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.

1.0.0 #

  • Initial version, created by Stagehand

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

Use this package as a library

1. Depend on it

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


dependencies:
  request_extras: ^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:request_extras/request_extras.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/src/headers/download_headers.dart.

Run dartfmt to format lib/src/headers/download_headers.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev.8.1 <3.0.0
Dev dependencies
pedantic ^1.8.0+1
test ^1.9.3