mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Stop working around issue 6984.
Review URL: https://codereview.chromium.org//11464006 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15804 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
8bf95806ac
commit
01dd8fcb4e
6 changed files with 29 additions and 65 deletions
|
@ -29,7 +29,7 @@ void startServer() {
|
|||
(request, response) {
|
||||
response.statusCode = 400;
|
||||
response.contentLength = 0;
|
||||
closeResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
_server.addRequestHandler((request) => request.path == '/loop',
|
||||
|
@ -39,7 +39,7 @@ void startServer() {
|
|||
response.headers.set('location',
|
||||
serverUrl.resolve('/loop?${n + 1}').toString());
|
||||
response.contentLength = 0;
|
||||
closeResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
_server.addRequestHandler((request) => request.path == '/redirect',
|
||||
|
@ -47,7 +47,7 @@ void startServer() {
|
|||
response.statusCode = 302;
|
||||
response.headers.set('location', serverUrl.resolve('/').toString());
|
||||
response.contentLength = 0;
|
||||
closeResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
_server.defaultRequestHandler = (request, response) {
|
||||
|
@ -104,15 +104,6 @@ void stopServer() {
|
|||
_server = null;
|
||||
}
|
||||
|
||||
/// Closes [response] while ignoring the body of [request].
|
||||
///
|
||||
/// Due to issue 6984, it's necessary to drain the request body before closing
|
||||
/// the response.
|
||||
void closeResponse(HttpRequest request, HttpResponse response) {
|
||||
request.inputStream.onData = request.inputStream.read;
|
||||
request.inputStream.onClosed = response.outputStream.close;
|
||||
}
|
||||
|
||||
/// A matcher that matches JSON that parses to a value that matches the inner
|
||||
/// matcher.
|
||||
Matcher parse(matcher) => new _Parse(matcher);
|
||||
|
|
|
@ -666,31 +666,6 @@ Future _doProcess(Function fn, String executable, List<String> args, workingDir,
|
|||
return fn(executable, args, options);
|
||||
}
|
||||
|
||||
/// Closes [response] while ignoring the body of [request]. Returns a Future
|
||||
/// that completes once the response is closed.
|
||||
///
|
||||
/// Due to issue 6984, it's necessary to drain the request body before closing
|
||||
/// the response.
|
||||
Future closeHttpResponse(HttpRequest request, HttpResponse response) {
|
||||
// TODO(nweiz): remove this when issue 4061 is fixed.
|
||||
var stackTrace;
|
||||
try {
|
||||
throw "";
|
||||
} catch (_, localStackTrace) {
|
||||
stackTrace = localStackTrace;
|
||||
}
|
||||
|
||||
var completer = new Completer();
|
||||
request.inputStream.onError = (e) =>
|
||||
completer.completeException(e, stackTrace);
|
||||
request.inputStream.onData = request.inputStream.read;
|
||||
request.inputStream.onClosed = () {
|
||||
response.outputStream.close();
|
||||
completer.complete(null);
|
||||
};
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps [input] to provide a timeout. If [input] completes before
|
||||
* [milliseconds] have passed, then the return value completes in the same way.
|
||||
|
|
|
@ -166,13 +166,11 @@ Future<Client> _authorize() {
|
|||
if (queryString == null) queryString = '';
|
||||
response.statusCode = 302;
|
||||
response.headers.set('location', 'http://pub.dartlang.org/authorized');
|
||||
return Futures.wait([
|
||||
closeHttpResponse(request, response),
|
||||
grant.handleAuthorizationResponse(queryToMap(queryString))
|
||||
]);
|
||||
}).transform((results) {
|
||||
response.outputStream.close();
|
||||
return grant.handleAuthorizationResponse(queryToMap(queryString));
|
||||
}).transform((client) {
|
||||
server.close();
|
||||
return results[1];
|
||||
return client;
|
||||
}), completer);
|
||||
});
|
||||
server.listen('127.0.0.1', 0);
|
||||
|
|
|
@ -27,7 +27,7 @@ main() {
|
|||
expect(request.headers.value('authorization'),
|
||||
equals('Bearer access token'));
|
||||
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
pub.kill();
|
||||
|
@ -46,7 +46,7 @@ main() {
|
|||
expect(request.headers.value('authorization'),
|
||||
equals('Bearer access token'));
|
||||
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
pub.kill();
|
||||
|
@ -83,7 +83,7 @@ main() {
|
|||
expect(request.headers.value('authorization'),
|
||||
equals('Bearer new access token'));
|
||||
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
pub.shouldExit();
|
||||
|
@ -111,7 +111,7 @@ main() {
|
|||
expect(request.headers.value('authorization'),
|
||||
equals('Bearer new access token'));
|
||||
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
pub.kill();
|
||||
|
@ -135,7 +135,7 @@ main() {
|
|||
expect(request.headers.value('authorization'),
|
||||
equals('Bearer new access token'));
|
||||
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
pub.kill();
|
||||
|
|
|
@ -13,7 +13,7 @@ import '../../pub/io.dart';
|
|||
|
||||
void handleUploadForm(ScheduledServer server, [Map body]) {
|
||||
server.handle('GET', '/packages/versions/new.json', (request, response) {
|
||||
return server.url.chain((url) {
|
||||
return server.url.transform((url) {
|
||||
expect(request.headers.value('authorization'),
|
||||
equals('Bearer access token'));
|
||||
|
||||
|
@ -29,7 +29,7 @@ void handleUploadForm(ScheduledServer server, [Map body]) {
|
|||
|
||||
response.headers.contentType = new ContentType("application", "json");
|
||||
response.outputStream.writeString(JSON.stringify(body));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ void handleUpload(ScheduledServer server) {
|
|||
server.handle('POST', '/upload', (request, response) {
|
||||
// TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate
|
||||
// that the request body is correctly formatted. See issue 6952.
|
||||
return server.url.chain((url) {
|
||||
return server.url.transform((url) {
|
||||
response.statusCode = 302;
|
||||
response.headers.set('location', url.resolve('/create').toString());
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ main() {
|
|||
response.outputStream.writeString(JSON.stringify({
|
||||
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
|
||||
}));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextLine(), equals('Package test_pkg 1.0.0 uploaded!'));
|
||||
|
@ -84,7 +84,7 @@ main() {
|
|||
response.outputStream.writeString(JSON.stringify({
|
||||
'error': {'message': 'your token sucks'}
|
||||
}));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your '
|
||||
|
@ -145,7 +145,7 @@ main() {
|
|||
response.outputStream.writeString(JSON.stringify({
|
||||
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
|
||||
}));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
pub.shouldExit(0);
|
||||
|
@ -165,7 +165,7 @@ main() {
|
|||
response.outputStream.writeString(JSON.stringify({
|
||||
'error': {'message': 'your request sucked'}
|
||||
}));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('your request sucked'));
|
||||
|
@ -181,7 +181,7 @@ main() {
|
|||
|
||||
server.handle('GET', '/packages/versions/new.json', (request, response) {
|
||||
response.outputStream.writeString('{not json');
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('Invalid server response:'));
|
||||
|
@ -314,7 +314,7 @@ main() {
|
|||
|
||||
server.handle('POST', '/upload', (request, response) {
|
||||
// don't set the location header
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('Failed to upload the package.'));
|
||||
|
@ -335,7 +335,7 @@ main() {
|
|||
response.outputStream.writeString(JSON.stringify({
|
||||
'error': {'message': 'Your package was too boring.'}
|
||||
}));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('Your package was too boring.'));
|
||||
|
@ -353,7 +353,7 @@ main() {
|
|||
|
||||
server.handle('GET', '/create', (request, response) {
|
||||
response.outputStream.writeString('{not json');
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('Invalid server response:'));
|
||||
|
@ -374,7 +374,7 @@ main() {
|
|||
server.handle('GET', '/create', (request, response) {
|
||||
response.statusCode = 400;
|
||||
response.outputStream.writeString(JSON.stringify(body));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('Invalid server response:'));
|
||||
|
@ -394,7 +394,7 @@ main() {
|
|||
var body = {'success': 'Your package was awesome.'};
|
||||
server.handle('GET', '/create', (request, response) {
|
||||
response.outputStream.writeString(JSON.stringify(body));
|
||||
return closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
expectLater(pub.nextErrLine(), equals('Invalid server response:'));
|
||||
|
|
|
@ -108,7 +108,7 @@ void serve([List<Descriptor> contents]) {
|
|||
} catch (e) {
|
||||
response.statusCode = 404;
|
||||
response.contentLength = 0;
|
||||
closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -117,14 +117,14 @@ void serve([List<Descriptor> contents]) {
|
|||
response.statusCode = 200;
|
||||
response.contentLength = data.length;
|
||||
response.outputStream.write(data);
|
||||
closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
|
||||
future.handleException((e) {
|
||||
print("Exception while handling ${request.uri}: $e");
|
||||
response.statusCode = 500;
|
||||
response.reasonPhrase = e.message;
|
||||
closeHttpResponse(request, response);
|
||||
response.outputStream.close();
|
||||
});
|
||||
};
|
||||
_server.listen("127.0.0.1", 0);
|
||||
|
|
Loading…
Reference in a new issue