Skip to content

Commit c27d6c7

Browse files
authored
Merge pull request #1416 from dart-lang/merge-http_multi_server-package
Merge `package:http_multi_server`
2 parents e166181 + b6a4eeb commit c27d6c7

File tree

16 files changed

+1177
-9
lines changed

16 files changed

+1177
-9
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:http_multi_server"
3+
about: "Create a bug or file a feature request against package:http_multi_server."
4+
labels: "package:http_multi_server"
5+
---

.github/labeler.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@
22

33
'type-infra':
44
- changed-files:
5-
- any-glob-to-any-file: '.github/**'
5+
- any-glob-to-any-file: '.github/**'
66

77
'package:cronet_http':
88
- changed-files:
9-
- any-glob-to-any-file: 'pkgs/cronet_http/**'
9+
- any-glob-to-any-file: 'pkgs/cronet_http/**'
1010

1111
'package:cupertino_http':
1212
- changed-files:
13-
- any-glob-to-any-file: 'pkgs/cupertino_http/**'
13+
- any-glob-to-any-file: 'pkgs/cupertino_http/**'
1414

1515
'package:http':
1616
- changed-files:
17-
- any-glob-to-any-file: 'pkgs/http/**'
17+
- any-glob-to-any-file: 'pkgs/http/**'
1818

1919
'package:http2':
2020
- changed-files:
21-
- any-glob-to-any-file: 'pkgs/http2/**'
21+
- any-glob-to-any-file: 'pkgs/http2/**'
2222

23-
'package:http_parser':
23+
'package:http_client_conformance_tests':
2424
- changed-files:
25-
- any-glob-to-any-file: 'pkgs/http_parser/**'
25+
- any-glob-to-any-file: 'pkgs/http_client_conformance_tests/**'
2626

27-
'package:http_client_conformance_tests':
27+
'package:http_multi_server':
28+
- changed-files:
29+
- any-glob-to-any-file: 'pkgs/http_multi_server/**'
30+
31+
'package:http_parser':
2832
- changed-files:
29-
- any-glob-to-any-file: 'pkgs/http_client_conformance_tests/**'
33+
- any-glob-to-any-file: 'pkgs/http_parser/**'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: package:http_multi_server
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- '.github/workflows/http_multi_server.yaml'
9+
- 'pkgs/http_multi_server/**'
10+
pull_request:
11+
paths:
12+
- '.github/workflows/http_multi_server.yaml'
13+
- 'pkgs/http_multi_server/**'
14+
schedule:
15+
- cron: "0 0 * * 0"
16+
17+
defaults:
18+
run:
19+
working-directory: pkgs/http_multi_server/
20+
21+
env:
22+
PUB_ENVIRONMENT: bot.github
23+
24+
jobs:
25+
# Check code formatting and static analysis on a single OS (linux)
26+
# against Dart dev.
27+
analyze:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
sdk: [dev]
33+
steps:
34+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
35+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
36+
with:
37+
sdk: ${{ matrix.sdk }}
38+
- id: install
39+
name: Install dependencies
40+
run: dart pub get
41+
- name: Check formatting
42+
run: dart format --output=none --set-exit-if-changed .
43+
if: always() && steps.install.outcome == 'success'
44+
- name: Analyze code
45+
run: dart analyze --fatal-infos
46+
if: always() && steps.install.outcome == 'success'
47+
48+
# Run tests on a matrix consisting of two dimensions:
49+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
50+
# 2. release channel: dev
51+
test:
52+
needs: analyze
53+
runs-on: ${{ matrix.os }}
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
# Add macos-latest and/or windows-latest if relevant for this package.
58+
os: [ubuntu-latest]
59+
sdk: [3.2, dev]
60+
steps:
61+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
62+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
63+
with:
64+
sdk: ${{ matrix.sdk }}
65+
- id: install
66+
name: Install dependencies
67+
run: dart pub get
68+
- name: Run VM tests
69+
run: dart test --platform vm
70+
if: always() && steps.install.outcome == 'success'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and the browser.
1616
| [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) |
1717
| [http2](pkgs/http2/) | A HTTP/2 implementation in Dart. | [![pub package](https://img.shields.io/pub/v/http2.svg)](https://pub.dev/packages/http2) |
1818
| [http_client_conformance_tests](pkgs/http_client_conformance_tests/) | A library that tests whether implementations of package:http's `Client` class behave as expected. | |
19+
| [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) |
1920
| [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) |
2021
| [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) |
2122
| [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) |

pkgs/http_multi_server/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Don’t commit the following directories created by pub.
2+
.buildlog
3+
.dart_tool/
4+
.packages
5+
build/
6+
7+
# Or the files created by dart2js.
8+
*.dart.js
9+
*.js_
10+
*.js.deps
11+
*.js.map
12+
13+
# Include when developing application packages.
14+
pubspec.lock

pkgs/http_multi_server/.test_config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"test_package": {
3+
"platforms": ["vm"]
4+
}
5+
}

pkgs/http_multi_server/CHANGELOG.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## 3.2.2
2+
3+
* Require Dart 3.2
4+
* Move to `dart-lang/http` monorepo.
5+
6+
## 3.2.1
7+
8+
* Populate the pubspec `repository` field.
9+
10+
## 3.2.0
11+
12+
* Honor the `preserveHeaderCase` argument to `MultiHeaders.set` and `.add`.
13+
14+
## 3.1.0
15+
16+
* Add `HttpMultiServer.bindSecure` to match `HttpMultiServer.bind`.
17+
18+
## 3.0.1
19+
20+
* Fix an issue where `bind` would bind to the `anyIPv6` address in unsupported
21+
environments.
22+
23+
## 3.0.0
24+
25+
* Migrate to null safety.
26+
27+
## 2.2.0
28+
29+
* Preparation for [HttpHeaders change]. Update signature of `MultiHeaders.add()`
30+
and `MultiHeaders.set()` to match new signature of `HttpHeaders`. The
31+
parameter is not yet forwarded and will not behave as expected.
32+
33+
[HttpHeaders change]: https://github.com/dart-lang/sdk/issues/39657
34+
35+
## 2.1.0
36+
37+
* Add `HttpMultiServer.bind` static which centralizes logic around common local
38+
serving scenarios - handling a more flexible 'localhost' and listening on
39+
'any' hostname.
40+
* Update SDK constraints to `>=2.1.0 <3.0.0`.
41+
42+
## 2.0.6
43+
44+
* If there is a problem starting a loopback Ipv6 server, don't keep the Ipv4
45+
server open when throwing the exception.
46+
47+
## 2.0.5
48+
49+
* Update SDK constraints to `>=2.0.0-dev <3.0.0`.
50+
51+
## 2.0.4
52+
53+
* Declare support for `async` 2.0.0.
54+
55+
## 2.0.3
56+
57+
* Fix `HttpMultiServer.loopback()` and `.loopbackSecure()` for environments that
58+
don't support IPv4.
59+
60+
## 2.0.2
61+
62+
* Fix a dependency that was incorrectly marked as dev-only.
63+
64+
## 2.0.1
65+
66+
* Fix most strong mode errors and warnings.
67+
68+
## 2.0.0
69+
70+
* **Breaking:** Change the signature of `HttpMultiServer.loopbackSecure()` to
71+
match the new Dart 1.13 `HttpServer.bindSecure()` signature. This removes the
72+
`certificateName` named parameter and adds the required `context` parameter
73+
and the named `v6Only` and `shared` parameters.
74+
75+
* Added `v6Only` and `shared` parameters to `HttpMultiServer.loopback()` to
76+
match `HttpServer.bind()`.
77+
78+
## 1.3.2
79+
80+
* Eventually stop retrying port allocation if it fails repeatedly.
81+
82+
* Properly detect socket errors caused by already-in-use addresses.
83+
84+
## 1.3.1
85+
86+
* `loopback()` and `loopbackSecure()` recover gracefully if an ephemeral port is
87+
requested and the located port isn't available on both IPv4 and IPv6.
88+
89+
## 1.3.0
90+
91+
* Add support for `HttpServer.autoCompress`.
92+
93+
## 1.2.0
94+
95+
* Add support for `HttpServer.defaultResponseHeaders.clear`.
96+
97+
* Fix `HttpServer.defaultResponseHeaders.remove` and `.removeAll`.
98+
99+
## 1.1.0
100+
101+
* Add support for `HttpServer.defaultResponseHeaders`.
102+
103+
## 1.0.2
104+
105+
* Remove the workaround for [issue 19815][].
106+
107+
## 1.0.1
108+
109+
* Ignore errors from one of the servers if others are still bound. In
110+
particular, this works around [issue 19815][] on some Windows machines where
111+
IPv6 failure isn't discovered until we try to connect to the socket.
112+
113+
[issue 19815]: https://code.google.com/p/dart/issues/detail?id=19815

pkgs/http_multi_server/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2014, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/http_multi_server/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[![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)
2+
[![pub package](https://img.shields.io/pub/v/http_multi_server.svg)](https://pub.dev/packages/http_multi_server)
3+
[![package publisher](https://img.shields.io/pub/publisher/http_multi_server.svg)](https://pub.dev/packages/http_multi_server/publisher)
4+
5+
An implementation of `dart:io`'s [HttpServer][] that wraps multiple servers and
6+
forwards methods to all of them. It's useful for serving the same application on
7+
multiple network interfaces while still having a unified way of controlling the
8+
servers. In particular, it supports serving on both the IPv4 and IPv6 loopback
9+
addresses using [HttpMultiServer.loopback][].
10+
11+
```dart
12+
import 'package:http_multi_server/http_multi_server.dart';
13+
import 'package:shelf/shelf.dart' as shelf;
14+
import 'package:shelf/shelf_io.dart' as shelf_io;
15+
16+
void main() async {
17+
// Both http://127.0.0.1:8080 and http://[::1]:8080 will be bound to the same
18+
// server.
19+
var server = await HttpMultiServer.loopback(8080);
20+
shelf_io.serveRequests(server, (request) {
21+
return shelf.Response.ok("Hello, world!");
22+
});
23+
}
24+
```
25+
26+
[HttpServer]: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-io.HttpServer
27+
28+
[HttpMultiServer.loopback]: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/http_multi_server/http_multi_server.HttpMultiServer#id_loopback
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# https://dart.dev/tools/analysis#the-analysis-options-file
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
8+
linter:
9+
rules:
10+
- avoid_bool_literals_in_conditional_expressions
11+
- avoid_classes_with_only_static_members
12+
- avoid_private_typedef_functions
13+
- avoid_redundant_argument_values
14+
- avoid_returning_this
15+
- avoid_unused_constructor_parameters
16+
- cancel_subscriptions
17+
- cascade_invocations
18+
- join_return_with_assignment
19+
- literal_only_boolean_expressions
20+
- no_adjacent_strings_in_list
21+
- no_runtimeType_toString
22+
- prefer_const_declarations
23+
- prefer_expression_function_bodies
24+
- prefer_final_locals
25+
- use_string_buffers
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:http_multi_server/http_multi_server.dart';
6+
import 'package:shelf/shelf.dart' as shelf;
7+
import 'package:shelf/shelf_io.dart' as shelf_io;
8+
9+
void main() async {
10+
// Both http://127.0.0.1:8080 and http://[::1]:8080 will be bound to the same
11+
// server.
12+
final server = await HttpMultiServer.loopback(8080);
13+
shelf_io.serveRequests(
14+
server,
15+
(request) => shelf.Response.ok('Hello, world!'),
16+
);
17+
}

0 commit comments

Comments
 (0)