OLD | NEW |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
1 library lish.utils; | 5 library lish.utils; |
| 6 |
2 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 |
3 import 'package:scheduled_test/scheduled_test.dart'; | 9 import 'package:scheduled_test/scheduled_test.dart'; |
4 import 'package:scheduled_test/scheduled_server.dart'; | 10 import 'package:scheduled_test/scheduled_server.dart'; |
5 import 'package:shelf/shelf.dart' as shelf; | 11 import 'package:shelf/shelf.dart' as shelf; |
| 12 |
6 import '../../lib/src/io.dart'; | 13 import '../../lib/src/io.dart'; |
| 14 |
7 void handleUploadForm(ScheduledServer server, [Map body]) { | 15 void handleUploadForm(ScheduledServer server, [Map body]) { |
8 server.handle('GET', '/api/packages/versions/new', (request) { | 16 server.handle('GET', '/api/packages/versions/new', (request) { |
9 return server.url.then((url) { | 17 return server.url.then((url) { |
10 expect( | 18 expect( |
11 request.headers, | 19 request.headers, |
12 containsPair('authorization', 'Bearer access token')); | 20 containsPair('authorization', 'Bearer access token')); |
| 21 |
13 if (body == null) { | 22 if (body == null) { |
14 body = { | 23 body = { |
15 'url': url.resolve('/upload').toString(), | 24 'url': url.resolve('/upload').toString(), |
16 'fields': { | 25 'fields': { |
17 'field1': 'value1', | 26 'field1': 'value1', |
18 'field2': 'value2' | 27 'field2': 'value2' |
19 } | 28 } |
20 }; | 29 }; |
21 } | 30 } |
| 31 |
22 return new shelf.Response.ok(JSON.encode(body), headers: { | 32 return new shelf.Response.ok(JSON.encode(body), headers: { |
23 'content-type': 'application/json' | 33 'content-type': 'application/json' |
24 }); | 34 }); |
25 }); | 35 }); |
26 }); | 36 }); |
27 } | 37 } |
| 38 |
28 void handleUpload(ScheduledServer server) { | 39 void handleUpload(ScheduledServer server) { |
29 server.handle('POST', '/upload', (request) { | 40 server.handle('POST', '/upload', (request) { |
| 41 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate |
| 42 // that the request body is correctly formatted. See issue 6952. |
30 return drainStream( | 43 return drainStream( |
31 request.read()).then( | 44 request.read()).then( |
32 (_) => | 45 (_) => |
33 server.url).then((url) => new shelf.Response.found(url.resolve('
/create'))); | 46 server.url).then((url) => new shelf.Response.found(url.resolve('
/create'))); |
34 }); | 47 }); |
35 } | 48 } |
| 49 |
OLD | NEW |