Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 1e9b78c

Browse files
committed
Merge branch 'release/1.1.1'
2 parents c5f080d + 8a279e0 commit 1e9b78c

11 files changed

Lines changed: 75 additions & 90 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ $ bower install vue-resource
2222
```
2323

2424
### CDN
25-
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.1.0/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/vue-resource@1.1.0/dist/vue-resource.min.js).
25+
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.1.1/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/vue-resource@1.1.1/dist/vue-resource.min.js).
2626
```html
27-
<script src="https://cdn.jsdelivr.net/vue.resource/1.1.0/vue-resource.min.js"></script>
27+
<script src="https://cdn.jsdelivr.net/vue.resource/1.1.1/vue-resource.min.js"></script>
2828
```
2929

3030
## Example

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-resource",
33
"main": "dist/vue-resource.js",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"description": "The HTTP client for Vue.js",
66
"homepage": "https://github.com/vuejs/vue-resource",
77
"license": "MIT",

dist/vue-resource.common.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-resource v1.1.0
2+
* vue-resource v1.1.1
33
* https://github.com/vuejs/vue-resource
44
* Released under the MIT License.
55
*/
@@ -865,9 +865,9 @@ var body = function (request, next) {
865865

866866
return response.bodyText ? when(response.text(), function (text) {
867867

868-
var type = response.headers.get('Content-Type');
868+
var type = response.headers.get('Content-Type') || '';
869869

870-
if (isString(type) && type.indexOf('application/json') === 0) {
870+
if (type.indexOf('application/json') === 0 || isJson(text)) {
871871

872872
try {
873873
response.body = JSON.parse(text);
@@ -886,6 +886,13 @@ var body = function (request, next) {
886886
});
887887
};
888888

889+
function isJson(str) {
890+
891+
var start = str.match(/^\[|^\{(?!\{)/), end = {'[': /]$/, '{': /}$/};
892+
893+
return start && end[start[0]].test(str);
894+
}
895+
889896
/**
890897
* JSONP client.
891898
*/
@@ -950,19 +957,7 @@ var jsonp = function (request, next) {
950957
request.client = jsonpClient;
951958
}
952959

953-
next(function (response) {
954-
955-
if (request.method == 'JSONP') {
956-
957-
try {
958-
response.body = JSON.parse(response.body);
959-
} catch (e) {
960-
response.body = null;
961-
}
962-
963-
}
964-
965-
});
960+
next();
966961
};
967962

968963
/**
@@ -1016,6 +1011,8 @@ var header = function (request, next) {
10161011
* XMLHttp client.
10171012
*/
10181013

1014+
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
1015+
10191016
var xhrClient = function (request) {
10201017
return new PromiseObj(function (resolve) {
10211018

@@ -1047,10 +1044,6 @@ var xhrClient = function (request) {
10471044

10481045
xhr.open(request.method, request.getUrl(), true);
10491046

1050-
if ('responseType' in xhr) {
1051-
xhr.responseType = 'blob';
1052-
}
1053-
10541047
if (request.timeout) {
10551048
xhr.timeout = request.timeout;
10561049
}
@@ -1059,6 +1052,10 @@ var xhrClient = function (request) {
10591052
xhr.withCredentials = true;
10601053
}
10611054

1055+
if ('responseType' in xhr && SUPPORTS_BLOB) {
1056+
xhr.responseType = 'blob';
1057+
}
1058+
10621059
request.headers.forEach(function (value, name) {
10631060
xhr.setRequestHeader(name, value);
10641061
});

dist/vue-resource.es2015.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-resource v1.1.0
2+
* vue-resource v1.1.1
33
* https://github.com/vuejs/vue-resource
44
* Released under the MIT License.
55
*/
@@ -863,9 +863,9 @@ var body = function (request, next) {
863863

864864
return response.bodyText ? when(response.text(), function (text) {
865865

866-
var type = response.headers.get('Content-Type');
866+
var type = response.headers.get('Content-Type') || '';
867867

868-
if (isString(type) && type.indexOf('application/json') === 0) {
868+
if (type.indexOf('application/json') === 0 || isJson(text)) {
869869

870870
try {
871871
response.body = JSON.parse(text);
@@ -884,6 +884,13 @@ var body = function (request, next) {
884884
});
885885
};
886886

887+
function isJson(str) {
888+
889+
var start = str.match(/^\[|^\{(?!\{)/), end = {'[': /]$/, '{': /}$/};
890+
891+
return start && end[start[0]].test(str);
892+
}
893+
887894
/**
888895
* JSONP client.
889896
*/
@@ -948,19 +955,7 @@ var jsonp = function (request, next) {
948955
request.client = jsonpClient;
949956
}
950957

951-
next(function (response) {
952-
953-
if (request.method == 'JSONP') {
954-
955-
try {
956-
response.body = JSON.parse(response.body);
957-
} catch (e) {
958-
response.body = null;
959-
}
960-
961-
}
962-
963-
});
958+
next();
964959
};
965960

966961
/**
@@ -1014,6 +1009,8 @@ var header = function (request, next) {
10141009
* XMLHttp client.
10151010
*/
10161011

1012+
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
1013+
10171014
var xhrClient = function (request) {
10181015
return new PromiseObj(function (resolve) {
10191016

@@ -1045,10 +1042,6 @@ var xhrClient = function (request) {
10451042

10461043
xhr.open(request.method, request.getUrl(), true);
10471044

1048-
if ('responseType' in xhr) {
1049-
xhr.responseType = 'blob';
1050-
}
1051-
10521045
if (request.timeout) {
10531046
xhr.timeout = request.timeout;
10541047
}
@@ -1057,6 +1050,10 @@ var xhrClient = function (request) {
10571050
xhr.withCredentials = true;
10581051
}
10591052

1053+
if ('responseType' in xhr && SUPPORTS_BLOB) {
1054+
xhr.responseType = 'blob';
1055+
}
1056+
10601057
request.headers.forEach(function (value, name) {
10611058
xhr.setRequestHeader(name, value);
10621059
});

dist/vue-resource.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-resource v1.1.0
2+
* vue-resource v1.1.1
33
* https://github.com/vuejs/vue-resource
44
* Released under the MIT License.
55
*/
@@ -869,9 +869,9 @@ var body = function (request, next) {
869869

870870
return response.bodyText ? when(response.text(), function (text) {
871871

872-
var type = response.headers.get('Content-Type');
872+
var type = response.headers.get('Content-Type') || '';
873873

874-
if (isString(type) && type.indexOf('application/json') === 0) {
874+
if (type.indexOf('application/json') === 0 || isJson(text)) {
875875

876876
try {
877877
response.body = JSON.parse(text);
@@ -890,6 +890,13 @@ var body = function (request, next) {
890890
});
891891
};
892892

893+
function isJson(str) {
894+
895+
var start = str.match(/^\[|^\{(?!\{)/), end = {'[': /]$/, '{': /}$/};
896+
897+
return start && end[start[0]].test(str);
898+
}
899+
893900
/**
894901
* JSONP client.
895902
*/
@@ -954,19 +961,7 @@ var jsonp = function (request, next) {
954961
request.client = jsonpClient;
955962
}
956963

957-
next(function (response) {
958-
959-
if (request.method == 'JSONP') {
960-
961-
try {
962-
response.body = JSON.parse(response.body);
963-
} catch (e) {
964-
response.body = null;
965-
}
966-
967-
}
968-
969-
});
964+
next();
970965
};
971966

972967
/**
@@ -1020,6 +1015,8 @@ var header = function (request, next) {
10201015
* XMLHttp client.
10211016
*/
10221017

1018+
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
1019+
10231020
var xhrClient = function (request) {
10241021
return new PromiseObj(function (resolve) {
10251022

@@ -1051,10 +1048,6 @@ var xhrClient = function (request) {
10511048

10521049
xhr.open(request.method, request.getUrl(), true);
10531050

1054-
if ('responseType' in xhr) {
1055-
xhr.responseType = 'blob';
1056-
}
1057-
10581051
if (request.timeout) {
10591052
xhr.timeout = request.timeout;
10601053
}
@@ -1063,6 +1056,10 @@ var xhrClient = function (request) {
10631056
xhr.withCredentials = true;
10641057
}
10651058

1059+
if ('responseType' in xhr && SUPPORTS_BLOB) {
1060+
xhr.responseType = 'blob';
1061+
}
1062+
10661063
request.headers.forEach(function (value, name) {
10671064
xhr.setRequestHeader(name, value);
10681065
});

0 commit comments

Comments
 (0)