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 const int _HEADERS_BUFFER_SIZE = 8 * 1024; | 7 const int _HEADERS_BUFFER_SIZE = 8 * 1024; |
8 | 8 |
9 class _HttpIncoming extends Stream<List<int>> { | 9 class _HttpIncoming extends Stream<List<int>> { |
10 final int _transferLength; | 10 final int _transferLength; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 class _HttpRequest extends _HttpInboundMessage implements HttpRequest { | 84 class _HttpRequest extends _HttpInboundMessage implements HttpRequest { |
85 final HttpResponse response; | 85 final HttpResponse response; |
86 | 86 |
87 final _HttpServer _httpServer; | 87 final _HttpServer _httpServer; |
88 | 88 |
89 final _HttpConnection _httpConnection; | 89 final _HttpConnection _httpConnection; |
90 | 90 |
91 _HttpSession _session; | 91 _HttpSession _session; |
92 | 92 |
| 93 Uri _requestedUri; |
| 94 |
93 _HttpRequest(_HttpResponse this.response, | 95 _HttpRequest(_HttpResponse this.response, |
94 _HttpIncoming _incoming, | 96 _HttpIncoming _incoming, |
95 _HttpServer this._httpServer, | 97 _HttpServer this._httpServer, |
96 _HttpConnection this._httpConnection) | 98 _HttpConnection this._httpConnection) |
97 : super(_incoming) { | 99 : super(_incoming) { |
98 if (headers.protocolVersion == "1.1") { | 100 if (headers.protocolVersion == "1.1") { |
99 response.headers.chunkedTransferEncoding = true; | 101 response.headers.chunkedTransferEncoding = true; |
100 response.headers.persistentConnection = headers.persistentConnection; | 102 response.headers.persistentConnection = headers.persistentConnection; |
101 } | 103 } |
102 | 104 |
(...skipping 17 matching lines...) Expand all Loading... |
120 void onDone(), | 122 void onDone(), |
121 bool cancelOnError}) { | 123 bool cancelOnError}) { |
122 return _incoming.listen(onData, | 124 return _incoming.listen(onData, |
123 onError: onError, | 125 onError: onError, |
124 onDone: onDone, | 126 onDone: onDone, |
125 cancelOnError: cancelOnError); | 127 cancelOnError: cancelOnError); |
126 } | 128 } |
127 | 129 |
128 Uri get uri => _incoming.uri; | 130 Uri get uri => _incoming.uri; |
129 | 131 |
| 132 Uri get requestedUri { |
| 133 if (_requestedUri == null) { |
| 134 var proto = headers['x-forwarded-proto']; |
| 135 var scheme = proto != null ? proto.first : |
| 136 _httpConnection._socket is SecureSocket ? "https" : "http"; |
| 137 var host = headers['x-forwarded-host']; |
| 138 if (host != null) { |
| 139 host = host.first; |
| 140 } else { |
| 141 host = headers['host']; |
| 142 if (host != null) { |
| 143 host = host.first; |
| 144 } else { |
| 145 host = "${_httpServer.address.host}:${_httpServer.port}"; |
| 146 } |
| 147 } |
| 148 _requestedUri = Uri.parse("$scheme://$host$uri"); |
| 149 } |
| 150 return _requestedUri; |
| 151 } |
| 152 |
130 String get method => _incoming.method; | 153 String get method => _incoming.method; |
131 | 154 |
132 HttpSession get session { | 155 HttpSession get session { |
133 if (_session != null) { | 156 if (_session != null) { |
134 if (_session._destroyed) { | 157 if (_session._destroyed) { |
135 // It's destroyed, clear it. | 158 // It's destroyed, clear it. |
136 _session = null; | 159 _session = null; |
137 // Create new session object by calling recursive. | 160 // Create new session object by calling recursive. |
138 return session; | 161 return session; |
139 } | 162 } |
(...skipping 2441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2581 | 2604 |
2582 String _getHttpVersion() { | 2605 String _getHttpVersion() { |
2583 var version = Platform.version; | 2606 var version = Platform.version; |
2584 // Only include major and minor version numbers. | 2607 // Only include major and minor version numbers. |
2585 int index = version.indexOf('.', version.indexOf('.') + 1); | 2608 int index = version.indexOf('.', version.indexOf('.') + 1); |
2586 version = version.substring(0, index); | 2609 version = version.substring(0, index); |
2587 return 'Dart/$version (dart:io)'; | 2610 return 'Dart/$version (dart:io)'; |
2588 } | 2611 } |
2589 | 2612 |
2590 | 2613 |
OLD | NEW |