OLD | NEW |
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 /// A Shelf adapter for handling [HttpRequest] objects from `dart:io`. | 5 /// A Shelf adapter for handling [HttpRequest] objects from `dart:io`. |
6 /// | 6 /// |
7 /// One can provide an instance of [HttpServer] as the `requests` parameter in | 7 /// One can provide an instance of [HttpServer] as the `requests` parameter in |
8 /// [serveRequests]. | 8 /// [serveRequests]. |
9 /// | 9 /// |
10 /// This adapter supports request hijacking; see [Request.hijack]. It also | 10 /// This adapter supports request hijacking; see [Request.hijack]. It also |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 /// Creates a new [Request] from the provided [HttpRequest]. | 110 /// Creates a new [Request] from the provided [HttpRequest]. |
111 Request _fromHttpRequest(HttpRequest request) { | 111 Request _fromHttpRequest(HttpRequest request) { |
112 var headers = <String, String>{}; | 112 var headers = <String, String>{}; |
113 request.headers.forEach((k, v) { | 113 request.headers.forEach((k, v) { |
114 // Multiple header values are joined with commas. | 114 // Multiple header values are joined with commas. |
115 // See http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-21#page-22 | 115 // See http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-21#page-22 |
116 headers[k] = v.join(','); | 116 headers[k] = v.join(','); |
117 }); | 117 }); |
118 | 118 |
119 onHijack(callback) { | 119 void onHijack(callback) { |
120 return request.response | 120 request.response |
121 .detachSocket(writeHeaders: false) | 121 .detachSocket(writeHeaders: false) |
122 .then((socket) => callback(socket, socket)); | 122 .then((socket) => callback(socket, socket)); |
123 } | 123 } |
124 | 124 |
125 return new Request(request.method, request.requestedUri, | 125 return new Request(request.method, request.requestedUri, |
126 protocolVersion: request.protocolVersion, | 126 protocolVersion: request.protocolVersion, |
127 headers: headers, | 127 headers: headers, |
128 body: request, | 128 body: request, |
129 onHijack: onHijack); | 129 onHijack: onHijack); |
130 } | 130 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 chain = new Chain.forTrace(stackTrace); | 175 chain = new Chain.forTrace(stackTrace); |
176 } | 176 } |
177 chain = chain | 177 chain = chain |
178 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse; | 178 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse; |
179 | 179 |
180 stderr.writeln('ERROR - ${new DateTime.now()}'); | 180 stderr.writeln('ERROR - ${new DateTime.now()}'); |
181 stderr.writeln(message); | 181 stderr.writeln(message); |
182 stderr.writeln(chain); | 182 stderr.writeln(chain); |
183 return new Response.internalServerError(); | 183 return new Response.internalServerError(); |
184 } | 184 } |
OLD | NEW |