OLD | NEW |
| (Empty) |
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 | |
5 library lish.utils; | |
6 | |
7 import 'dart:io'; | |
8 import 'dart:json' as json; | |
9 | |
10 import 'package:scheduled_test/scheduled_test.dart'; | |
11 import 'package:scheduled_test/scheduled_server.dart'; | |
12 | |
13 import '../../../pub/io.dart'; | |
14 import '../test_pub.dart'; | |
15 | |
16 void handleUploadForm(ScheduledServer server, [Map body]) { | |
17 server.handle('GET', '/packages/versions/new.json', (request) { | |
18 return server.url.then((url) { | |
19 expect(request.headers.value('authorization'), | |
20 equals('Bearer access token')); | |
21 | |
22 if (body == null) { | |
23 body = { | |
24 'url': url.resolve('/upload').toString(), | |
25 'fields': { | |
26 'field1': 'value1', | |
27 'field2': 'value2' | |
28 } | |
29 }; | |
30 } | |
31 | |
32 request.response.headers.contentType = | |
33 new ContentType("application", "json"); | |
34 request.response.write(json.stringify(body)); | |
35 request.response.close(); | |
36 }); | |
37 }); | |
38 } | |
39 | |
40 void handleUpload(ScheduledServer server) { | |
41 server.handle('POST', '/upload', (request) { | |
42 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate | |
43 // that the request body is correctly formatted. See issue 6952. | |
44 return drainStream(request).then((_) { | |
45 return server.url; | |
46 }).then((url) { | |
47 request.response.statusCode = 302; | |
48 request.response.headers.set( | |
49 'location', url.resolve('/create').toString()); | |
50 request.response.close(); | |
51 }); | |
52 }); | |
53 } | |
54 | |
OLD | NEW |