| 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 dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 // The close queue handles graceful closing of HTTP connections. When | 7 // The close queue handles graceful closing of HTTP connections. When |
| 8 // a connection is added to the queue it will enter a wait state | 8 // a connection is added to the queue it will enter a wait state |
| 9 // waiting for all data written and possibly socket shutdown from | 9 // waiting for all data written and possibly socket shutdown from |
| 10 // peer. | 10 // peer. |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 493 |
| 494 void _streamClose() { | 494 void _streamClose() { |
| 495 _ensureHeadersSent(); | 495 _ensureHeadersSent(); |
| 496 _state = _HttpRequestResponseBase.DONE; | 496 _state = _HttpRequestResponseBase.DONE; |
| 497 // Stop tracking no pending write events. | 497 // Stop tracking no pending write events. |
| 498 _httpConnection._onNoPendingWrites = null; | 498 _httpConnection._onNoPendingWrites = null; |
| 499 // Ensure that any trailing data is written. | 499 // Ensure that any trailing data is written. |
| 500 _writeDone(); | 500 _writeDone(); |
| 501 // Indicate to the connection that the response handling is done. | 501 // Indicate to the connection that the response handling is done. |
| 502 _httpConnection._responseClosed(); | 502 _httpConnection._responseClosed(); |
| 503 if (_streamClosedHandler != null) { |
| 504 new Timer(0, (_) => _streamClosedHandler()); |
| 505 } |
| 503 } | 506 } |
| 504 | 507 |
| 505 void _streamSetNoPendingWriteHandler(callback()) { | 508 void _streamSetNoPendingWriteHandler(callback()) { |
| 506 if (_state != _HttpRequestResponseBase.DONE) { | 509 if (_state != _HttpRequestResponseBase.DONE) { |
| 507 _httpConnection._onNoPendingWrites = callback; | 510 _httpConnection._onNoPendingWrites = callback; |
| 508 } | 511 } |
| 509 } | 512 } |
| 510 | 513 |
| 511 void _streamSetCloseHandler(callback()) { | 514 void _streamSetClosedHandler(callback()) { |
| 512 // TODO(sgjesse): Handle this. | 515 _streamClosedHandler = callback; |
| 513 } | 516 } |
| 514 | 517 |
| 515 void _streamSetErrorHandler(callback(e)) { | 518 void _streamSetErrorHandler(callback(e)) { |
| 516 _streamErrorHandler = callback; | 519 _streamErrorHandler = callback; |
| 517 } | 520 } |
| 518 | 521 |
| 519 String _findReasonPhrase(int statusCode) { | 522 String _findReasonPhrase(int statusCode) { |
| 520 if (_reasonPhrase != null) { | 523 if (_reasonPhrase != null) { |
| 521 return _reasonPhrase; | 524 return _reasonPhrase; |
| 522 } | 525 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 // Write headers. | 617 // Write headers. |
| 615 _headers._finalize(_protocolVersion); | 618 _headers._finalize(_protocolVersion); |
| 616 bool allWritten = _writeHeaders(); | 619 bool allWritten = _writeHeaders(); |
| 617 _state = _HttpRequestResponseBase.HEADER_SENT; | 620 _state = _HttpRequestResponseBase.HEADER_SENT; |
| 618 return allWritten; | 621 return allWritten; |
| 619 } | 622 } |
| 620 | 623 |
| 621 int _statusCode; // Response status code. | 624 int _statusCode; // Response status code. |
| 622 String _reasonPhrase; // Response reason phrase. | 625 String _reasonPhrase; // Response reason phrase. |
| 623 _HttpOutputStream _outputStream; | 626 _HttpOutputStream _outputStream; |
| 627 Function _streamClosedHandler; |
| 624 Function _streamErrorHandler; | 628 Function _streamErrorHandler; |
| 625 } | 629 } |
| 626 | 630 |
| 627 | 631 |
| 628 class _HttpInputStream extends _BaseDataInputStream implements InputStream { | 632 class _HttpInputStream extends _BaseDataInputStream implements InputStream { |
| 629 _HttpInputStream(_HttpRequestResponseBase this._requestOrResponse) { | 633 _HttpInputStream(_HttpRequestResponseBase this._requestOrResponse) { |
| 630 _checkScheduleCallbacks(); | 634 _checkScheduleCallbacks(); |
| 631 } | 635 } |
| 632 | 636 |
| 633 int available() { | 637 int available() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 696 |
| 693 void destroy() { | 697 void destroy() { |
| 694 throw "Not implemented"; | 698 throw "Not implemented"; |
| 695 } | 699 } |
| 696 | 700 |
| 697 void set onNoPendingWrites(void callback()) { | 701 void set onNoPendingWrites(void callback()) { |
| 698 _requestOrResponse._streamSetNoPendingWriteHandler(callback); | 702 _requestOrResponse._streamSetNoPendingWriteHandler(callback); |
| 699 } | 703 } |
| 700 | 704 |
| 701 void set onClosed(void callback()) { | 705 void set onClosed(void callback()) { |
| 702 _requestOrResponse._streamSetCloseHandler(callback); | 706 _requestOrResponse._streamSetClosedHandler(callback); |
| 703 } | 707 } |
| 704 | 708 |
| 705 void set onError(void callback(e)) { | 709 void set onError(void callback(e)) { |
| 706 _requestOrResponse._streamSetErrorHandler(callback); | 710 _requestOrResponse._streamSetErrorHandler(callback); |
| 707 } | 711 } |
| 708 | 712 |
| 709 _HttpRequestResponseBase _requestOrResponse; | 713 _HttpRequestResponseBase _requestOrResponse; |
| 710 } | 714 } |
| 711 | 715 |
| 712 | 716 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 } | 1196 } |
| 1193 | 1197 |
| 1194 void _streamClose() { | 1198 void _streamClose() { |
| 1195 _ensureHeadersSent(); | 1199 _ensureHeadersSent(); |
| 1196 _state = _HttpRequestResponseBase.DONE; | 1200 _state = _HttpRequestResponseBase.DONE; |
| 1197 // Stop tracking no pending write events. | 1201 // Stop tracking no pending write events. |
| 1198 _httpConnection._onNoPendingWrites = null; | 1202 _httpConnection._onNoPendingWrites = null; |
| 1199 // Ensure that any trailing data is written. | 1203 // Ensure that any trailing data is written. |
| 1200 _writeDone(); | 1204 _writeDone(); |
| 1201 _connection._requestClosed(); | 1205 _connection._requestClosed(); |
| 1206 if (_streamClosedHandler != null) { |
| 1207 new Timer(0, (_) => _streamClosedHandler()); |
| 1208 } |
| 1202 } | 1209 } |
| 1203 | 1210 |
| 1204 void _streamSetNoPendingWriteHandler(callback()) { | 1211 void _streamSetNoPendingWriteHandler(callback()) { |
| 1205 if (_state != _HttpRequestResponseBase.DONE) { | 1212 if (_state != _HttpRequestResponseBase.DONE) { |
| 1206 _httpConnection._onNoPendingWrites = callback; | 1213 _httpConnection._onNoPendingWrites = callback; |
| 1207 } | 1214 } |
| 1208 } | 1215 } |
| 1209 | 1216 |
| 1210 void _streamSetCloseHandler(callback()) { | 1217 void _streamSetClosedHandler(callback()) { |
| 1211 // TODO(sgjesse): Handle this. | 1218 _streamClosedHandler = callback; |
| 1212 } | 1219 } |
| 1213 | 1220 |
| 1214 void _streamSetErrorHandler(callback(e)) { | 1221 void _streamSetErrorHandler(callback(e)) { |
| 1215 _streamErrorHandler = callback; | 1222 _streamErrorHandler = callback; |
| 1216 } | 1223 } |
| 1217 | 1224 |
| 1218 void _writeHeader() { | 1225 void _writeHeader() { |
| 1219 List<int> data; | 1226 List<int> data; |
| 1220 | 1227 |
| 1221 // Write request line. | 1228 // Write request line. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 // Write headers. | 1265 // Write headers. |
| 1259 _headers._finalize("1.1"); | 1266 _headers._finalize("1.1"); |
| 1260 _writeHeaders(); | 1267 _writeHeaders(); |
| 1261 _state = _HttpRequestResponseBase.HEADER_SENT; | 1268 _state = _HttpRequestResponseBase.HEADER_SENT; |
| 1262 } | 1269 } |
| 1263 | 1270 |
| 1264 String _method; | 1271 String _method; |
| 1265 Uri _uri; | 1272 Uri _uri; |
| 1266 _HttpClientConnection _connection; | 1273 _HttpClientConnection _connection; |
| 1267 _HttpOutputStream _outputStream; | 1274 _HttpOutputStream _outputStream; |
| 1275 Function _streamClosedHandler; |
| 1268 Function _streamErrorHandler; | 1276 Function _streamErrorHandler; |
| 1269 bool _emptyBody = true; | 1277 bool _emptyBody = true; |
| 1270 } | 1278 } |
| 1271 | 1279 |
| 1272 class _HttpClientResponse | 1280 class _HttpClientResponse |
| 1273 extends _HttpRequestResponseBase | 1281 extends _HttpRequestResponseBase |
| 1274 implements HttpClientResponse { | 1282 implements HttpClientResponse { |
| 1275 _HttpClientResponse(_HttpClientConnection connection) | 1283 _HttpClientResponse(_HttpClientConnection connection) |
| 1276 : super(connection) { | 1284 : super(connection) { |
| 1277 _connection = connection; | 1285 _connection = connection; |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 | 2314 |
| 2307 | 2315 |
| 2308 class _RedirectInfo implements RedirectInfo { | 2316 class _RedirectInfo implements RedirectInfo { |
| 2309 const _RedirectInfo(int this.statusCode, | 2317 const _RedirectInfo(int this.statusCode, |
| 2310 String this.method, | 2318 String this.method, |
| 2311 Uri this.location); | 2319 Uri this.location); |
| 2312 final int statusCode; | 2320 final int statusCode; |
| 2313 final String method; | 2321 final String method; |
| 2314 final Uri location; | 2322 final Uri location; |
| 2315 } | 2323 } |
| OLD | NEW |