Skip to content

Commit

Permalink
Merge pull request #1416 from dart-lang/merge-http_multi_server-package
Browse files Browse the repository at this point in the history
Merge `package:http_multi_server`
  • Loading branch information
mosuem authored Dec 17, 2024
2 parents e166181 + b6a4eeb commit c27d6c7
Show file tree
Hide file tree
Showing 16 changed files with 1,177 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/http_multi_server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:http_multi_server"
about: "Create a bug or file a feature request against package:http_multi_server."
labels: "package:http_multi_server"
---
22 changes: 13 additions & 9 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@

'type-infra':
- changed-files:
- any-glob-to-any-file: '.github/**'
- any-glob-to-any-file: '.github/**'

'package:cronet_http':
- changed-files:
- any-glob-to-any-file: 'pkgs/cronet_http/**'
- any-glob-to-any-file: 'pkgs/cronet_http/**'

'package:cupertino_http':
- changed-files:
- any-glob-to-any-file: 'pkgs/cupertino_http/**'
- any-glob-to-any-file: 'pkgs/cupertino_http/**'

'package:http':
- changed-files:
- any-glob-to-any-file: 'pkgs/http/**'
- any-glob-to-any-file: 'pkgs/http/**'

'package:http2':
- changed-files:
- any-glob-to-any-file: 'pkgs/http2/**'
- any-glob-to-any-file: 'pkgs/http2/**'

'package:http_parser':
'package:http_client_conformance_tests':
- changed-files:
- any-glob-to-any-file: 'pkgs/http_parser/**'
- any-glob-to-any-file: 'pkgs/http_client_conformance_tests/**'

'package:http_client_conformance_tests':
'package:http_multi_server':
- changed-files:
- any-glob-to-any-file: 'pkgs/http_multi_server/**'

'package:http_parser':
- changed-files:
- any-glob-to-any-file: 'pkgs/http_client_conformance_tests/**'
- any-glob-to-any-file: 'pkgs/http_parser/**'
70 changes: 70 additions & 0 deletions .github/workflows/http_multi_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: package:http_multi_server

on:
push:
branches:
- master
paths:
- '.github/workflows/http_multi_server.yaml'
- 'pkgs/http_multi_server/**'
pull_request:
paths:
- '.github/workflows/http_multi_server.yaml'
- 'pkgs/http_multi_server/**'
schedule:
- cron: "0 0 * * 0"

defaults:
run:
working-directory: pkgs/http_multi_server/

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'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and the browser.
| [http](pkgs/http/) | A composable, multi-platform, Future-based API for HTTP requests. | [![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/http) |
| [http2](pkgs/http2/) | A HTTP/2 implementation in Dart. | [![pub package](https://img.shields.io/pub/v/http2.svg)](https://pub.dev/packages/http2) |
| [http_client_conformance_tests](pkgs/http_client_conformance_tests/) | A library that tests whether implementations of package:http's `Client` class behave as expected. | |
| [http_multi_server](pkgs/http_multi_server/) | A `dart:io` `HttpServer` wrapper that handles requests from multiple servers. | [![pub package](https://img.shields.io/pub/v/http_multi_server.svg)](https://pub.dev/packages/http_multi_server) |
| [http_parser](pkgs/http_parser/) | A platform-independent package for parsing and serializing HTTP formats. | [![pub package](https://img.shields.io/pub/v/http_parser.svg)](https://pub.dev/packages/http_parser) |
| [http_profile](pkgs/http_profile/) | A library used by HTTP client authors to integrate with the DevTools Network View. | [![pub package](https://img.shields.io/pub/v/http_profile.svg)](https://pub.dev/packages/http_profile) |
| [ok_http](pkgs/ok_http/) | An Android Flutter plugin that provides access to the [OkHttp](https://square.github.io/okhttp/) HTTP client and the OkHttp [WebSocket](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-web-socket/index.html) API. | [![pub package](https://img.shields.io/pub/v/ok_http.svg)](https://pub.dev/packages/ok_http) |
Expand Down
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"]
}
}
113 changes: 113 additions & 0 deletions pkgs/http_multi_server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
## 3.2.2

* Require Dart 3.2
* Move to `dart-lang/http` monorepo.

## 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/actions/workflows/http_multi_server.yaml/badge.svg)](https://github.com/dart-lang/http/actions/workflows/http_multi_server.yaml)
[![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
17 changes: 17 additions & 0 deletions pkgs/http_multi_server/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

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 c27d6c7

Please sign in to comment.