Skip to content

Commit

Permalink
Merge package:http_multi_server into the http monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Dec 6, 2024
2 parents 79470d0 + 2b0b562 commit 658b4c4
Show file tree
Hide file tree
Showing 16 changed files with 1,213 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkgs/http_multi_server/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dependabot configuration file.
# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
labels:
- autosubmit
groups:
github-actions:
patterns:
- "*"
37 changes: 37 additions & 0 deletions pkgs/http_multi_server/.github/workflows/no-response.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# A workflow to close issues where the author hasn't responded to a request for
# more information; see https://github.com/actions/stale.

name: No Response

# Run as a daily cron.
on:
schedule:
# Every day at 8am
- cron: '0 8 * * *'

# All permissions not specified are set to 'none'.
permissions:
issues: write
pull-requests: write

jobs:
no-response:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'dart-lang' }}
steps:
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e
with:
# Don't automatically mark inactive issues+PRs as stale.
days-before-stale: -1
# Close needs-info issues and PRs after 14 days of inactivity.
days-before-close: 14
stale-issue-label: "needs-info"
close-issue-message: >
Without additional information we're not able to resolve this issue.
Feel free to add more info or respond to any questions above and we
can reopen the case. Thanks for your contribution!
stale-pr-label: "needs-info"
close-pr-message: >
Without additional information we're not able to resolve this PR.
Feel free to add more info or respond to any questions above.
Thanks for your contribution!
17 changes: 17 additions & 0 deletions pkgs/http_multi_server/.github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# A CI configuration to auto-publish pub packages.

name: Publish

on:
pull_request:
branches: [ master ]
push:
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]

jobs:
publish:
if: ${{ github.repository_owner == 'dart-lang' }}
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
permissions:
id-token: write # Required for authentication using OIDC
pull-requests: write # Required for writing the pull request note
61 changes: 61 additions & 0 deletions pkgs/http_multi_server/.github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Dart CI

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.2, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
14 changes: 14 additions & 0 deletions pkgs/http_multi_server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Don’t commit the following directories created by pub.
.buildlog
.dart_tool/
.packages
build/

# Or the files created by dart2js.
*.dart.js
*.js_
*.js.deps
*.js.map

# Include when developing application packages.
pubspec.lock
5 changes: 5 additions & 0 deletions pkgs/http_multi_server/.test_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"test_package": {
"platforms": ["vm"]
}
}
112 changes: 112 additions & 0 deletions pkgs/http_multi_server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
## 3.2.2-wip

* Require Dart 3.2

## 3.2.1

* Populate the pubspec `repository` field.

## 3.2.0

* Honor the `preserveHeaderCase` argument to `MultiHeaders.set` and `.add`.

## 3.1.0

* Add `HttpMultiServer.bindSecure` to match `HttpMultiServer.bind`.

## 3.0.1

* Fix an issue where `bind` would bind to the `anyIPv6` address in unsupported
environments.

## 3.0.0

* Migrate to null safety.

## 2.2.0

* Preparation for [HttpHeaders change]. Update signature of `MultiHeaders.add()`
and `MultiHeaders.set()` to match new signature of `HttpHeaders`. The
parameter is not yet forwarded and will not behave as expected.

[HttpHeaders change]: https://github.com/dart-lang/sdk/issues/39657

## 2.1.0

* Add `HttpMultiServer.bind` static which centralizes logic around common local
serving scenarios - handling a more flexible 'localhost' and listening on
'any' hostname.
* Update SDK constraints to `>=2.1.0 <3.0.0`.

## 2.0.6

* If there is a problem starting a loopback Ipv6 server, don't keep the Ipv4
server open when throwing the exception.

## 2.0.5

* Update SDK constraints to `>=2.0.0-dev <3.0.0`.

## 2.0.4

* Declare support for `async` 2.0.0.

## 2.0.3

* Fix `HttpMultiServer.loopback()` and `.loopbackSecure()` for environments that
don't support IPv4.

## 2.0.2

* Fix a dependency that was incorrectly marked as dev-only.

## 2.0.1

* Fix most strong mode errors and warnings.

## 2.0.0

* **Breaking:** Change the signature of `HttpMultiServer.loopbackSecure()` to
match the new Dart 1.13 `HttpServer.bindSecure()` signature. This removes the
`certificateName` named parameter and adds the required `context` parameter
and the named `v6Only` and `shared` parameters.

* Added `v6Only` and `shared` parameters to `HttpMultiServer.loopback()` to
match `HttpServer.bind()`.

## 1.3.2

* Eventually stop retrying port allocation if it fails repeatedly.

* Properly detect socket errors caused by already-in-use addresses.

## 1.3.1

* `loopback()` and `loopbackSecure()` recover gracefully if an ephemeral port is
requested and the located port isn't available on both IPv4 and IPv6.

## 1.3.0

* Add support for `HttpServer.autoCompress`.

## 1.2.0

* Add support for `HttpServer.defaultResponseHeaders.clear`.

* Fix `HttpServer.defaultResponseHeaders.remove` and `.removeAll`.

## 1.1.0

* Add support for `HttpServer.defaultResponseHeaders`.

## 1.0.2

* Remove the workaround for [issue 19815][].

## 1.0.1

* Ignore errors from one of the servers if others are still bound. In
particular, this works around [issue 19815][] on some Windows machines where
IPv6 failure isn't discovered until we try to connect to the socket.

[issue 19815]: https://code.google.com/p/dart/issues/detail?id=19815
27 changes: 27 additions & 0 deletions pkgs/http_multi_server/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2014, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 changes: 28 additions & 0 deletions pkgs/http_multi_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[![Dart CI](https://github.com/dart-lang/http_multi_server/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/http_multi_server/actions/workflows/test-package.yml)
[![pub package](https://img.shields.io/pub/v/http_multi_server.svg)](https://pub.dev/packages/http_multi_server)
[![package publisher](https://img.shields.io/pub/publisher/http_multi_server.svg)](https://pub.dev/packages/http_multi_server/publisher)

An implementation of `dart:io`'s [HttpServer][] that wraps multiple servers and
forwards methods to all of them. It's useful for serving the same application on
multiple network interfaces while still having a unified way of controlling the
servers. In particular, it supports serving on both the IPv4 and IPv6 loopback
addresses using [HttpMultiServer.loopback][].

```dart
import 'package:http_multi_server/http_multi_server.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;
void main() async {
// Both http://127.0.0.1:8080 and http://[::1]:8080 will be bound to the same
// server.
var server = await HttpMultiServer.loopback(8080);
shelf_io.serveRequests(server, (request) {
return shelf.Response.ok("Hello, world!");
});
}
```

[HttpServer]: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-io.HttpServer

[HttpMultiServer.loopback]: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/http_multi_server/http_multi_server.HttpMultiServer#id_loopback
25 changes: 25 additions & 0 deletions pkgs/http_multi_server/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://dart.dev/tools/analysis#the-analysis-options-file
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_this
- avoid_unused_constructor_parameters
- cancel_subscriptions
- cascade_invocations
- join_return_with_assignment
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_runtimeType_toString
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
- use_string_buffers
13 changes: 13 additions & 0 deletions pkgs/http_multi_server/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:http_multi_server/http_multi_server.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;

void main() async {
// Both http://127.0.0.1:8080 and http://[::1]:8080 will be bound to the same
// server.
final server = await HttpMultiServer.loopback(8080);
shelf_io.serveRequests(
server,
(request) => shelf.Response.ok('Hello, world!'),
);
}
Loading

0 comments on commit 658b4c4

Please sign in to comment.