Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: lib/shelf_io.dart

Issue 1030013003: Fix null response handling. (Closed) Base URL: git@github.com:dart-lang/shelf@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 // If the request wasn't hijacked, we shouldn't be seeing this exception. 78 // If the request wasn't hijacked, we shouldn't be seeing this exception.
79 return _logError( 79 return _logError(
80 "Caught HijackException, but the request wasn't hijacked.", 80 "Caught HijackException, but the request wasn't hijacked.",
81 stackTrace); 81 stackTrace);
82 } 82 }
83 83
84 return _logError('Error thrown by handler.\n$error', stackTrace); 84 return _logError('Error thrown by handler.\n$error', stackTrace);
85 }).then((response) { 85 }).then((response) {
86 if (response == null) { 86 if (response == null) {
87 response = _logError('null response from handler.'); 87 return _writeResponse(
88 _logError('null response from handler.'), request.response);
88 } else if (shelfRequest.canHijack) { 89 } else if (shelfRequest.canHijack) {
89 return _writeResponse(response, request.response); 90 return _writeResponse(response, request.response);
90 } 91 }
91 92
92 var message = new StringBuffer() 93 var message = new StringBuffer()
93 ..writeln("Got a response for hijacked request " 94 ..writeln("Got a response for hijacked request "
94 "${shelfRequest.method} ${shelfRequest.requestedUri}:") 95 "${shelfRequest.method} ${shelfRequest.requestedUri}:")
95 ..writeln(response.statusCode); 96 ..writeln(response.statusCode);
96 response.headers 97 response.headers
97 .forEach((key, value) => message.writeln("${key}: ${value}")); 98 .forEach((key, value) => message.writeln("${key}: ${value}"));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 chain = new Chain.forTrace(stackTrace); 158 chain = new Chain.forTrace(stackTrace);
158 } 159 }
159 chain = chain 160 chain = chain
160 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse; 161 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse;
161 162
162 stderr.writeln('ERROR - ${new DateTime.now()}'); 163 stderr.writeln('ERROR - ${new DateTime.now()}');
163 stderr.writeln(message); 164 stderr.writeln(message);
164 stderr.writeln(chain); 165 stderr.writeln(chain);
165 return new Response.internalServerError(); 166 return new Response.internalServerError();
166 } 167 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698