@@ -51,33 +51,27 @@ class ApplicationInstanceConfiguration {
51
51
/// A copy constructor
52
52
ApplicationInstanceConfiguration .fromConfiguration (
53
53
ApplicationInstanceConfiguration config)
54
- : this .address = config.address,
55
- this .port = config.port,
56
- this .isIpv6Only = config.isIpv6Only,
57
- this .isUsingClientCertificate = config.isUsingClientCertificate,
58
- this .serverCertificateName = config.serverCertificateName,
59
- this .shared = config.shared;
54
+ : this .address = config.address,
55
+ this .port = config.port,
56
+ this .isIpv6Only = config.isIpv6Only,
57
+ this .isUsingClientCertificate = config.isUsingClientCertificate,
58
+ this .serverCertificateName = config.serverCertificateName,
59
+ this .shared = config.shared;
60
60
}
61
61
62
62
/// A abstract class that concrete subclasses will implement to provide request handling behavior.
63
63
///
64
64
/// [Application] s set up HTTP(s) listeners, but do not do anything with them. The behavior of how an application
65
- /// responds to requests is defined by its [ApplicationPipeline] .
66
- abstract class ApplicationPipeline {
65
+ /// responds to requests is defined by its [ApplicationPipeline] . Instances of this class must implement the
66
+ /// [handleRequest] method from [RequestHandler] - this is the entry point of all requests into this pipeline.
67
+ abstract class ApplicationPipeline implements RequestHandler {
67
68
68
69
/// Passed in options for this pipeline from its owning [Application] .
69
70
///
70
71
/// These values give an opportunity for a pipeline to have a customization point within attachTo., like running
71
72
/// the owning [Application] in 'Development' or 'Production' mode. This property will always be set prior to invoking attachTo, but may be null
72
73
/// if the user did not set any configuration values.
73
74
Map <String , dynamic > options;
74
-
75
- /// Allows an [ApplicationPipeline] to handle HTTP(s) requests from its [Application] .
76
- ///
77
- /// Implementors of [ApplicationPipeline] must override this method to respond to an [Application] 's requests.
78
- /// The return value is the first [RequestHandler] that will be the initial [ResourceRequest] handler.
79
- /// The [initialHandler] will likely have handlers attached to it.
80
- RequestHandler initialHandler ();
81
75
}
82
76
83
77
/// A container for web server applications.
@@ -94,7 +88,7 @@ class Application {
94
88
///
95
89
/// This must be configured prior to [start] ing the [Application] .
96
90
ApplicationInstanceConfiguration configuration =
97
- new ApplicationInstanceConfiguration ();
91
+ new ApplicationInstanceConfiguration ();
98
92
99
93
/// The type of [ApplicationPipeline] that configures how requests are handled.
100
94
///
@@ -119,7 +113,7 @@ class Application {
119
113
120
114
for (int i = 0 ; i < numberOfInstances; i++ ) {
121
115
var config =
122
- new ApplicationInstanceConfiguration .fromConfiguration (configuration);
116
+ new ApplicationInstanceConfiguration .fromConfiguration (configuration);
123
117
124
118
var serverRecord = await _spawn (config, i + 1 );
125
119
servers.add (serverRecord);
@@ -140,7 +134,7 @@ class Application {
140
134
var initialMessage = new _InitialServerMessage (
141
135
pipelineTypeName, pipelineLibraryURI, config, identifier, receivePort.sendPort);
142
136
var isolate =
143
- await Isolate .spawn (_Server .entry, initialMessage, paused: true );
137
+ await Isolate .spawn (_Server .entry, initialMessage, paused: true );
144
138
isolate.addErrorListener (receivePort.sendPort);
145
139
146
140
return new _ServerRecord (isolate, receivePort, identifier);
@@ -153,7 +147,6 @@ class _Server {
153
147
HttpServer server;
154
148
ApplicationPipeline pipeline;
155
149
int identifier;
156
- RequestHandler initialHandler;
157
150
158
151
_Server (this .pipeline, this .configuration, this .identifier, this .parentMessagePort);
159
152
@@ -164,42 +157,41 @@ class _Server {
164
157
server.serverHeader = "monadart/${this .identifier }" ;
165
158
166
159
pipeline.options = configuration.pipelineOptions;
167
- initialHandler = pipeline.initialHandler ();
168
160
server.map ((httpReq) => new ResourceRequest (httpReq))
169
- .listen (initialHandler .handleRequest);
161
+ .listen (pipeline .handleRequest);
170
162
};
171
163
172
164
if (configuration.serverCertificateName != null ) {
173
165
HttpServer
174
- .bindSecure (configuration.address, configuration.port,
175
- certificateName: configuration.serverCertificateName,
176
- v6Only: configuration.isIpv6Only,
177
- shared: configuration.shared)
178
- .then (onBind);
166
+ .bindSecure (configuration.address, configuration.port,
167
+ certificateName: configuration.serverCertificateName,
168
+ v6Only: configuration.isIpv6Only,
169
+ shared: configuration.shared)
170
+ .then (onBind);
179
171
} else if (configuration.isUsingClientCertificate) {
180
172
HttpServer
181
- .bindSecure (configuration.address, configuration.port,
182
- requestClientCertificate: true ,
183
- v6Only: configuration.isIpv6Only,
184
- shared: configuration.shared)
185
- .then (onBind);
173
+ .bindSecure (configuration.address, configuration.port,
174
+ requestClientCertificate: true ,
175
+ v6Only: configuration.isIpv6Only,
176
+ shared: configuration.shared)
177
+ .then (onBind);
186
178
} else {
187
179
HttpServer
188
- .bind (configuration.address, configuration.port,
189
- v6Only: configuration.isIpv6Only, shared: configuration.shared)
190
- .then (onBind);
180
+ .bind (configuration.address, configuration.port,
181
+ v6Only: configuration.isIpv6Only, shared: configuration.shared)
182
+ .then (onBind);
191
183
}
192
184
}
193
185
194
186
static void entry (_InitialServerMessage params) {
195
187
var pipelineSourceLibraryMirror =
196
- currentMirrorSystem ().libraries[params.pipelineLibraryURI];
188
+ currentMirrorSystem ().libraries[params.pipelineLibraryURI];
197
189
var pipelineTypeMirror = pipelineSourceLibraryMirror.declarations[
198
- new Symbol (params.pipelineTypeName)] as ClassMirror ;
190
+ new Symbol (params.pipelineTypeName)] as ClassMirror ;
199
191
200
192
var app = pipelineTypeMirror.newInstance (new Symbol ("" ), []).reflectee;
201
193
var server =
202
- new _Server (app, params.configuration, params.identifier, params.parentMessagePort);
194
+ new _Server (app, params.configuration, params.identifier, params.parentMessagePort);
203
195
204
196
server.start ();
205
197
}
@@ -225,5 +217,5 @@ class _InitialServerMessage {
225
217
int identifier;
226
218
227
219
_InitialServerMessage (this .pipelineTypeName, this .pipelineLibraryURI,
228
- this .configuration, this .identifier, this .parentMessagePort);
229
- }
220
+ this .configuration, this .identifier, this .parentMessagePort);
221
+ }
0 commit comments