mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
Use the request module for fetching screenshots. Makes it easier to use https if necessary.
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
var util = require('util')
|
||||
var http = require('http')
|
||||
var stream = require('stream')
|
||||
var url = require('url')
|
||||
|
||||
var Promise = require('bluebird')
|
||||
var request = require('request')
|
||||
|
||||
module.exports = function(path, options) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
http.get(url.resolve(options.storageUrl, path))
|
||||
.on('response', function(res) {
|
||||
var res = request.get(url.resolve(options.storageUrl, path))
|
||||
, ret = new stream.Readable().wrap(res) // Wrap old-style stream
|
||||
|
||||
res.on('response', function(res) {
|
||||
if (res.statusCode !== 200) {
|
||||
reject(new Error(util.format('HTTP %d', res.statusCode)))
|
||||
}
|
||||
else {
|
||||
resolve(res)
|
||||
resolve(ret)
|
||||
}
|
||||
})
|
||||
.on('error', reject)
|
||||
|
||||
Reference in New Issue
Block a user