Skip to content
pubscout

shelf_enforces_ssl

1.2.1, released 3 years ago by jxstxn.dev

Middleware that blocks non-HTTPS requests to a Shelf or Dart Frog server.

WASM-ready
$ flutter pub add shelf_enforces_ssl
Source repository

What it does

It intercepts incoming requests and rejects any that are not over HTTPS, optionally returning a custom error response. The middleware can be added to a Shelf pipeline or wrapped for Dart Frog usage.

AI-written summary of version 1.2.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to enforce HTTPS on a Shelf or Dart Frog API
  • Your server is exposed directly to the internet and you want to reject HTTP traffic
  • You want a quick, declarative way to add SSL enforcement without custom routing logic

Skip it when

  • Your traffic is already terminated at a reverse proxy that guarantees HTTPS
  • You are using a framework that already provides SSL enforcement

Strengths

  • Simple to add to existing Shelf pipelines
  • Supports custom error responses
  • Compatible with Dart 3 and newer
  • No build_runner or code generation required

Weaknesses

  • Only works with Shelf or Dart Frog
  • Does not handle HTTPS termination at load balancers
  • No support for other server frameworks

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Add the package to pubspec, import, and add enforceSSL() to your Pipeline or Dart Frog handler.

import 'package:shelf/shelf.dart';
import 'package:shelf_enforces_ssl/shelf_enforces_ssl.dart';

var handler = const Pipeline()
    .addMiddleware(enforceSSL())
    .addMiddleware(logRequests())
    .addHandler(_echoRequest);

Alternatives

Packages that do the same job and could replace shelf_enforces_ssl.

  • http2

    An HTTP/2 implementation in Dart for low-level transport and pooled HTTP/2 requests.

  • dio

    A powerful HTTP networking package for Dart and Flutter with interceptors and request cancellation.

  • native_dio_adapter

    A Dio HTTP client adapter that uses native platform HTTP stacks via cupertino_http and cronet_http.

  • relic

    Lightweight web server framework inspired by Shelf, with typed APIs and a high‑performance native Zig adapter.

Works with

Packages commonly used together with shelf_enforces_ssl: ones it builds on, ones built on it, and its own family.