OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of http_server; | 5 part of http_server; |
6 | 6 |
7 class _HttpBodyHandlerTransformer | 7 class _HttpBodyHandlerTransformer |
8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> { | 8 implements StreamTransformer<HttpRequest, HttpRequestBody> { |
9 final Encoding _defaultEncoding; | 9 final Encoding _defaultEncoding; |
10 _HttpBodyHandlerTransformer(this._defaultEncoding); | |
11 | 10 |
12 void handleData(HttpRequest request, EventSink<HttpRequestBody> sink) { | 11 const _HttpBodyHandlerTransformer(this._defaultEncoding); |
13 _HttpBodyHandler.processRequest(request, _defaultEncoding) | 12 |
14 .then(sink.add, onError: sink.addError); | 13 Stream<HttpRequestBody> bind(Stream<HttpRequest> stream) { |
| 14 return new Stream<HttpRequestBody>.eventTransformed( |
| 15 stream, |
| 16 (EventSink<HttpRequestBody> sink) => |
| 17 new _HttpBodyHandlerTransformerSink(_defaultEncoding, sink)); |
15 } | 18 } |
16 } | 19 } |
17 | 20 |
| 21 class _HttpBodyHandlerTransformerSink implements EventSink<HttpRequest> { |
| 22 final Encoding _defaultEncoding; |
| 23 final EventSink<HttpRequestBody> _outSink; |
| 24 |
| 25 _HttpBodyHandlerTransformerSink(this._defaultEncoding, this._outSink); |
| 26 |
| 27 void add(HttpRequest request) { |
| 28 _HttpBodyHandler.processRequest(request, _defaultEncoding) |
| 29 .then(_outSink.add, onError: _outSink.addError); |
| 30 } |
| 31 void addError(Object error, [StackTrace stackTrace]) { |
| 32 _outSink.addError(error, stackTrace); |
| 33 } |
| 34 void close() => _outSink.close(); |
| 35 } |
| 36 |
18 class _HttpBodyHandler { | 37 class _HttpBodyHandler { |
19 static Future<HttpRequestBody> processRequest( | 38 static Future<HttpRequestBody> processRequest( |
20 HttpRequest request, | 39 HttpRequest request, |
21 Encoding defaultEncoding) { | 40 Encoding defaultEncoding) { |
22 return process(request, request.headers, defaultEncoding) | 41 return process(request, request.headers, defaultEncoding) |
23 .then((body) => new _HttpRequestBody(request, body), | 42 .then((body) => new _HttpRequestBody(request, body), |
24 onError: (error) { | 43 onError: (error) { |
25 // Try to send BAD_REQUEST response. | 44 // Try to send BAD_REQUEST response. |
26 request.response.statusCode = HttpStatus.BAD_REQUEST; | 45 request.response.statusCode = HttpStatus.BAD_REQUEST; |
27 request.response.close(); | 46 request.response.close(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) | 209 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) |
191 : super(body.contentType, body.type, body.body), | 210 : super(body.contentType, body.type, body.body), |
192 this.response = response; | 211 this.response = response; |
193 | 212 |
194 int get statusCode => response.statusCode; | 213 int get statusCode => response.statusCode; |
195 | 214 |
196 String get reasonPhrase => response.reasonPhrase; | 215 String get reasonPhrase => response.reasonPhrase; |
197 | 216 |
198 HttpHeaders get headers => response.headers; | 217 HttpHeaders get headers => response.headers; |
199 } | 218 } |
OLD | NEW |