diff --git a/lib/request.js b/lib/request.js index d1e2b42..69ec49c 100644 --- a/lib/request.js +++ b/lib/request.js @@ -22,15 +22,20 @@ var Request = module.exports = function (xhr, params) { try { xhr.withCredentials = params.withCredentials } catch (e) {} - if (params.responseType) try { xhr.responseType = params.responseType } - catch (e) {} - xhr.open( params.method || 'GET', self.uri, true ); + if (params.responseType) { + try { + xhr.responseType = params.responseType + } catch (e) { + self.emit('error', e); + } + } + xhr.onerror = function(event) { self.emit('error', new Error('Network error')); }; diff --git a/test/request_url.js b/test/request_url.js index 1ff8e53..205aabb 100644 --- a/test/request_url.js +++ b/test/request_url.js @@ -86,3 +86,11 @@ test('Test withCredentials param', function(t) { t.end(); }); + +test('Test responseType param', function(t) { + var url = '/api/binary-endpoint'; + var request = http.request({url: url, responseType: 'arraybuffer'}, noop); + t.equal(request.xhr.responseType, 'arraybuffer', 'xhr.responseType should be set'); + t.end(); +}); +