OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library http_multi_server; | 5 library http_multi_server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'src/multi_headers.dart'; | 10 import 'src/multi_headers.dart'; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 /// listened to when this is called. | 86 /// listened to when this is called. |
87 HttpMultiServer(Iterable<HttpServer> servers) | 87 HttpMultiServer(Iterable<HttpServer> servers) |
88 : _servers = servers.toSet(), | 88 : _servers = servers.toSet(), |
89 defaultResponseHeaders = new MultiHeaders( | 89 defaultResponseHeaders = new MultiHeaders( |
90 servers.map((server) => server.defaultResponseHeaders)), | 90 servers.map((server) => server.defaultResponseHeaders)), |
91 super(mergeStreams(servers)); | 91 super(mergeStreams(servers)); |
92 | 92 |
93 /// Creates an [HttpServer] listening on all available loopback addresses for | 93 /// Creates an [HttpServer] listening on all available loopback addresses for |
94 /// this computer. | 94 /// this computer. |
95 /// | 95 /// |
96 /// If this computer supports both IPv4 and IPv6, this returns an | 96 /// See [HttpServer.bind]. |
97 /// [HttpMultiServer] listening to [port] on both loopback addresses. | 97 static Future<HttpServer> loopback(int port, {int backlog, bool v6Only: false, |
98 /// Otherwise, it returns a normal [HttpServer] listening only on the IPv4 | 98 bool shared: false}) { |
99 /// address. | |
100 /// | |
101 /// If [port] is 0, the same ephemeral port is used for both the IPv4 and IPv6 | |
102 /// addresses. | |
103 static Future<HttpServer> loopback(int port, {int backlog}) { | |
104 if (backlog == null) backlog = 0; | 99 if (backlog == null) backlog = 0; |
105 | 100 |
106 return _loopback(port, (address, port) => | 101 return _loopback(port, (address, port) => |
107 HttpServer.bind(address, port, backlog: backlog)); | 102 HttpServer.bind(address, port, |
| 103 backlog: backlog, v6Only: v6Only, shared: shared)); |
108 } | 104 } |
109 | 105 |
110 /// Like [loopback], but supports HTTPS requests. | 106 /// Like [loopback], but supports HTTPS requests. |
111 /// | 107 /// |
112 /// The certificate with nickname or distinguished name (DN) [certificateName] | 108 /// See [HttpServer.bindSecure]. |
113 /// is looked up in the certificate database, and is used as the server | 109 static Future<HttpServer> loopbackSecure(int port, SecurityContext context, |
114 /// certificate. If [requestClientCertificate] is true, the server will | 110 {int backlog, bool v6Only: false, bool requestClientCertificate: false, |
115 /// request clients to authenticate with a client certificate. | 111 bool shared: false}) { |
116 static Future<HttpServer> loopbackSecure(int port, {int backlog, | |
117 String certificateName, bool requestClientCertificate: false}) { | |
118 if (backlog == null) backlog = 0; | 112 if (backlog == null) backlog = 0; |
119 | 113 |
120 return _loopback(port, (address, port) => | 114 return _loopback(port, (address, port) => |
121 HttpServer.bindSecure(address, port, backlog: backlog, | 115 HttpServer.bindSecure(address, port, context, |
122 certificateName: certificateName, | 116 backlog: backlog, v6Only: v6Only, shared: shared, |
123 requestClientCertificate: requestClientCertificate)); | 117 requestClientCertificate: requestClientCertificate)); |
124 } | 118 } |
125 | 119 |
126 /// A helper method for initializing loopback servers. | 120 /// A helper method for initializing loopback servers. |
127 /// | 121 /// |
128 /// [bind] should forward to either [HttpServer.bind] or | 122 /// [bind] should forward to either [HttpServer.bind] or |
129 /// [HttpServer.bindSecure]. | 123 /// [HttpServer.bindSecure]. |
130 static Future<HttpServer> _loopback(int port, | 124 static Future<HttpServer> _loopback(int port, |
131 Future<HttpServer> bind(InternetAddress address, int port), | 125 Future<HttpServer> bind(InternetAddress address, int port), |
132 [int remainingRetries]) { | 126 [int remainingRetries]) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 for (var server in _servers) { | 165 for (var server in _servers) { |
172 var subInfo = server.connectionsInfo(); | 166 var subInfo = server.connectionsInfo(); |
173 info.total += subInfo.total; | 167 info.total += subInfo.total; |
174 info.active += subInfo.active; | 168 info.active += subInfo.active; |
175 info.idle += subInfo.idle; | 169 info.idle += subInfo.idle; |
176 info.closing += subInfo.closing; | 170 info.closing += subInfo.closing; |
177 } | 171 } |
178 return info; | 172 return info; |
179 } | 173 } |
180 } | 174 } |
OLD | NEW |