Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: pkg/http_multi_server/lib/http_multi_server.dart

Issue 469583002: Add support for HttpServer.defaultResponseHeaders to HttpMultiServer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http_multi_server/CHANGELOG.md ('k') | pkg/http_multi_server/lib/src/multi_headers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/utils.dart'; 11 import 'src/utils.dart';
11 12
12 /// An implementation of `dart:io`'s [HttpServer] that wraps multiple servers 13 /// An implementation of `dart:io`'s [HttpServer] that wraps multiple servers
13 /// and forwards methods to all of them. 14 /// and forwards methods to all of them.
14 /// 15 ///
15 /// This is useful for serving the same application on multiple network 16 /// This is useful for serving the same application on multiple network
16 /// interfaces while still having a unified way of controlling the servers. In 17 /// interfaces while still having a unified way of controlling the servers. In
17 /// particular, it supports serving on both the IPv4 and IPv6 loopback addresses 18 /// particular, it supports serving on both the IPv4 and IPv6 loopback addresses
18 /// using [HttpMultiServer.loopback]. 19 /// using [HttpMultiServer.loopback].
19 class HttpMultiServer extends StreamView<HttpRequest> implements HttpServer { 20 class HttpMultiServer extends StreamView<HttpRequest> implements HttpServer {
20 /// The wrapped servers. 21 /// The wrapped servers.
21 final Set<HttpServer> _servers; 22 final Set<HttpServer> _servers;
22 23
24 /// Returns the default value of the `Server` header for all responses
25 /// generated by each server.
26 ///
27 /// If the wrapped servers have different default values, it's not defined
28 /// which value is returned.
23 String get serverHeader => _servers.first.serverHeader; 29 String get serverHeader => _servers.first.serverHeader;
24 set serverHeader(String value) { 30 set serverHeader(String value) {
25 for (var server in _servers) { 31 for (var server in _servers) {
26 server.serverHeader = value; 32 server.serverHeader = value;
27 } 33 }
28 } 34 }
29 35
30 HttpHeaders get defaultResponseHeaders => 36 /// Returns the default set of headers added to all response objects.
31 throw new UnsupportedError('defaultResponseHeaders not supported'); 37 ///
38 /// If the wrapped servers have different default headers, it's not defined
39 /// which header is returned for accessor methods.
40 final HttpHeaders defaultResponseHeaders;
32 41
33 Duration get idleTimeout => _servers.first.idleTimeout; 42 Duration get idleTimeout => _servers.first.idleTimeout;
34 set idleTimeout(Duration value) { 43 set idleTimeout(Duration value) {
35 for (var server in _servers) { 44 for (var server in _servers) {
36 server.idleTimeout = value; 45 server.idleTimeout = value;
37 } 46 }
38 } 47 }
39 48
40 /// Returns the port that one of the wrapped servers is listening on. 49 /// Returns the port that one of the wrapped servers is listening on.
41 /// 50 ///
(...skipping 12 matching lines...) Expand all
54 server.sessionTimeout = value; 63 server.sessionTimeout = value;
55 } 64 }
56 } 65 }
57 66
58 /// Creates an [HttpMultiServer] wrapping [servers]. 67 /// Creates an [HttpMultiServer] wrapping [servers].
59 /// 68 ///
60 /// All [servers] should have the same configuration and none should be 69 /// All [servers] should have the same configuration and none should be
61 /// listened to when this is called. 70 /// listened to when this is called.
62 HttpMultiServer(Iterable<HttpServer> servers) 71 HttpMultiServer(Iterable<HttpServer> servers)
63 : _servers = servers.toSet(), 72 : _servers = servers.toSet(),
73 defaultResponseHeaders = new MultiHeaders(
74 servers.map((server) => server.defaultResponseHeaders)),
64 super(mergeStreams(servers)); 75 super(mergeStreams(servers));
65 76
66 /// Creates an [HttpServer] listening on all available loopback addresses for 77 /// Creates an [HttpServer] listening on all available loopback addresses for
67 /// this computer. 78 /// this computer.
68 /// 79 ///
69 /// If this computer supports both IPv4 and IPv6, this returns an 80 /// If this computer supports both IPv4 and IPv6, this returns an
70 /// [HttpMultiServer] listening to [port] on both loopback addresses. 81 /// [HttpMultiServer] listening to [port] on both loopback addresses.
71 /// Otherwise, it returns a normal [HttpServer] listening only on the IPv4 82 /// Otherwise, it returns a normal [HttpServer] listening only on the IPv4
72 /// address. 83 /// address.
73 /// 84 ///
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 for (var server in _servers) { 141 for (var server in _servers) {
131 var subInfo = server.connectionsInfo(); 142 var subInfo = server.connectionsInfo();
132 info.total += subInfo.total; 143 info.total += subInfo.total;
133 info.active += subInfo.active; 144 info.active += subInfo.active;
134 info.idle += subInfo.idle; 145 info.idle += subInfo.idle;
135 info.closing += subInfo.closing; 146 info.closing += subInfo.closing;
136 } 147 }
137 return info; 148 return info;
138 } 149 }
139 } 150 }
OLDNEW
« no previous file with comments | « pkg/http_multi_server/CHANGELOG.md ('k') | pkg/http_multi_server/lib/src/multi_headers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698