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

Commit f8377d5

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 37df5c7 + e50222e commit f8377d5

File tree

16 files changed

+256
-51
lines changed

16 files changed

+256
-51
lines changed

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.2/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/vue-resource@1.1.2/dist/vue-resource.min.js).
25+
Available on [jsdelivr](https://cdn.jsdelivr.net/vue.resource/1.2.0/vue-resource.min.js), [cdnjs](https://cdnjs.com/libraries/vue-resource) or [unpkg](https://unpkg.com/vue-resource@1.2.0/dist/vue-resource.min.js).
2626
```html
27-
<script src="https://cdn.jsdelivr.net/vue.resource/1.1.2/vue-resource.min.js"></script>
27+
<script src="https://cdn.jsdelivr.net/vue.resource/1.2.0/vue-resource.min.js"></script>
2828
```
2929

3030
## Example

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "vue-resource",
33
"main": "dist/vue-resource.js",
4-
"version": "1.1.2",
4+
"version": "1.2.0",
55
"description": "The HTTP client for Vue.js",
6-
"homepage": "https://github.com/vuejs/vue-resource",
6+
"homepage": "https://github.com/pagekit/vue-resource",
77
"license": "MIT",
88
"keywords": [
99
"vue",

build/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var package = require('../package.json');
66
var banner =
77
"/*!\n" +
88
" * vue-resource v" + package.version + "\n" +
9-
" * https://github.com/vuejs/vue-resource\n" +
9+
" * https://github.com/pagekit/vue-resource\n" +
1010
" * Released under the MIT License.\n" +
1111
" */\n";
1212

dist/vue-resource.common.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
2-
* vue-resource v1.1.2
3-
* https://github.com/vuejs/vue-resource
2+
* vue-resource v1.2.0
3+
* https://github.com/pagekit/vue-resource
44
* Released under the MIT License.
55
*/
66

@@ -888,7 +888,7 @@ function isJson(str) {
888888
}
889889

890890
/**
891-
* JSONP client.
891+
* JSONP client (Browser).
892892
*/
893893

894894
var jsonpClient = function (request) {
@@ -1002,7 +1002,7 @@ var header = function (request, next) {
10021002
};
10031003

10041004
/**
1005-
* XMLHttp client.
1005+
* XMLHttp client (Browser).
10061006
*/
10071007

10081008
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
@@ -1046,6 +1046,10 @@ var xhrClient = function (request) {
10461046
xhr.withCredentials = true;
10471047
}
10481048

1049+
if (!request.crossOrigin) {
1050+
request.headers.set('X-Requested-With', 'XMLHttpRequest');
1051+
}
1052+
10491053
if ('responseType' in xhr && SUPPORTS_BLOB) {
10501054
xhr.responseType = 'blob';
10511055
}
@@ -1062,6 +1066,43 @@ var xhrClient = function (request) {
10621066
});
10631067
};
10641068

1069+
/**
1070+
* Http client (Node).
1071+
*/
1072+
1073+
var nodeClient = function (request) {
1074+
1075+
var client = require('got');
1076+
1077+
return new PromiseObj(function (resolve) {
1078+
1079+
var url = request.getUrl();
1080+
var body = request.getBody();
1081+
var method = request.method;
1082+
var headers = {}, handler;
1083+
1084+
request.headers.forEach(function (value, name) {
1085+
headers[name] = value;
1086+
});
1087+
1088+
client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) {
1089+
1090+
var response = request.respondWith(resp.body, {
1091+
status: resp.statusCode,
1092+
statusText: trim(resp.statusMessage)
1093+
}
1094+
);
1095+
1096+
each(resp.headers, function (value, name) {
1097+
response.headers.set(name, value);
1098+
});
1099+
1100+
resolve(response);
1101+
1102+
}, function (error$$1) { return handler(error$$1.response); });
1103+
});
1104+
};
1105+
10651106
/**
10661107
* Base client.
10671108
*/
@@ -1125,7 +1166,7 @@ var Client = function (context) {
11251166

11261167
function sendRequest(request, resolve) {
11271168

1128-
var client = request.client || xhrClient;
1169+
var client = request.client || (inBrowser ? xhrClient : nodeClient);
11291170

11301171
resolve(client(request));
11311172
}
@@ -1299,7 +1340,6 @@ Request.prototype.respondWith = function respondWith (body, options$$1) {
12991340
* Service for sending network requests.
13001341
*/
13011342

1302-
var CUSTOM_HEADERS = {'X-Requested-With': 'XMLHttpRequest'};
13031343
var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'};
13041344
var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'};
13051345

@@ -1334,8 +1374,8 @@ Http.headers = {
13341374
post: JSON_CONTENT_TYPE,
13351375
patch: JSON_CONTENT_TYPE,
13361376
delete: JSON_CONTENT_TYPE,
1337-
custom: CUSTOM_HEADERS,
1338-
common: COMMON_HEADERS
1377+
common: COMMON_HEADERS,
1378+
custom: {}
13391379
};
13401380

13411381
Http.interceptors = [before, method, body, jsonp, header, cors];

dist/vue-resource.es2015.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
2-
* vue-resource v1.1.2
3-
* https://github.com/vuejs/vue-resource
2+
* vue-resource v1.2.0
3+
* https://github.com/pagekit/vue-resource
44
* Released under the MIT License.
55
*/
66

@@ -886,7 +886,7 @@ function isJson(str) {
886886
}
887887

888888
/**
889-
* JSONP client.
889+
* JSONP client (Browser).
890890
*/
891891

892892
var jsonpClient = function (request) {
@@ -1000,7 +1000,7 @@ var header = function (request, next) {
10001000
};
10011001

10021002
/**
1003-
* XMLHttp client.
1003+
* XMLHttp client (Browser).
10041004
*/
10051005

10061006
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
@@ -1044,6 +1044,10 @@ var xhrClient = function (request) {
10441044
xhr.withCredentials = true;
10451045
}
10461046

1047+
if (!request.crossOrigin) {
1048+
request.headers.set('X-Requested-With', 'XMLHttpRequest');
1049+
}
1050+
10471051
if ('responseType' in xhr && SUPPORTS_BLOB) {
10481052
xhr.responseType = 'blob';
10491053
}
@@ -1060,6 +1064,43 @@ var xhrClient = function (request) {
10601064
});
10611065
};
10621066

1067+
/**
1068+
* Http client (Node).
1069+
*/
1070+
1071+
var nodeClient = function (request) {
1072+
1073+
var client = require('got');
1074+
1075+
return new PromiseObj(function (resolve) {
1076+
1077+
var url = request.getUrl();
1078+
var body = request.getBody();
1079+
var method = request.method;
1080+
var headers = {}, handler;
1081+
1082+
request.headers.forEach(function (value, name) {
1083+
headers[name] = value;
1084+
});
1085+
1086+
client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) {
1087+
1088+
var response = request.respondWith(resp.body, {
1089+
status: resp.statusCode,
1090+
statusText: trim(resp.statusMessage)
1091+
}
1092+
);
1093+
1094+
each(resp.headers, function (value, name) {
1095+
response.headers.set(name, value);
1096+
});
1097+
1098+
resolve(response);
1099+
1100+
}, function (error$$1) { return handler(error$$1.response); });
1101+
});
1102+
};
1103+
10631104
/**
10641105
* Base client.
10651106
*/
@@ -1123,7 +1164,7 @@ var Client = function (context) {
11231164

11241165
function sendRequest(request, resolve) {
11251166

1126-
var client = request.client || xhrClient;
1167+
var client = request.client || (inBrowser ? xhrClient : nodeClient);
11271168

11281169
resolve(client(request));
11291170
}
@@ -1297,7 +1338,6 @@ Request.prototype.respondWith = function respondWith (body, options$$1) {
12971338
* Service for sending network requests.
12981339
*/
12991340

1300-
var CUSTOM_HEADERS = {'X-Requested-With': 'XMLHttpRequest'};
13011341
var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'};
13021342
var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'};
13031343

@@ -1332,8 +1372,8 @@ Http.headers = {
13321372
post: JSON_CONTENT_TYPE,
13331373
patch: JSON_CONTENT_TYPE,
13341374
delete: JSON_CONTENT_TYPE,
1335-
custom: CUSTOM_HEADERS,
1336-
common: COMMON_HEADERS
1375+
common: COMMON_HEADERS,
1376+
custom: {}
13371377
};
13381378

13391379
Http.interceptors = [before, method, body, jsonp, header, cors];

dist/vue-resource.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
2-
* vue-resource v1.1.2
3-
* https://github.com/vuejs/vue-resource
2+
* vue-resource v1.2.0
3+
* https://github.com/pagekit/vue-resource
44
* Released under the MIT License.
55
*/
66

@@ -892,7 +892,7 @@ function isJson(str) {
892892
}
893893

894894
/**
895-
* JSONP client.
895+
* JSONP client (Browser).
896896
*/
897897

898898
var jsonpClient = function (request) {
@@ -1006,7 +1006,7 @@ var header = function (request, next) {
10061006
};
10071007

10081008
/**
1009-
* XMLHttp client.
1009+
* XMLHttp client (Browser).
10101010
*/
10111011

10121012
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
@@ -1050,6 +1050,10 @@ var xhrClient = function (request) {
10501050
xhr.withCredentials = true;
10511051
}
10521052

1053+
if (!request.crossOrigin) {
1054+
request.headers.set('X-Requested-With', 'XMLHttpRequest');
1055+
}
1056+
10531057
if ('responseType' in xhr && SUPPORTS_BLOB) {
10541058
xhr.responseType = 'blob';
10551059
}
@@ -1066,6 +1070,43 @@ var xhrClient = function (request) {
10661070
});
10671071
};
10681072

1073+
/**
1074+
* Http client (Node).
1075+
*/
1076+
1077+
var nodeClient = function (request) {
1078+
1079+
var client = require('got');
1080+
1081+
return new PromiseObj(function (resolve) {
1082+
1083+
var url = request.getUrl();
1084+
var body = request.getBody();
1085+
var method = request.method;
1086+
var headers = {}, handler;
1087+
1088+
request.headers.forEach(function (value, name) {
1089+
headers[name] = value;
1090+
});
1091+
1092+
client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) {
1093+
1094+
var response = request.respondWith(resp.body, {
1095+
status: resp.statusCode,
1096+
statusText: trim(resp.statusMessage)
1097+
}
1098+
);
1099+
1100+
each(resp.headers, function (value, name) {
1101+
response.headers.set(name, value);
1102+
});
1103+
1104+
resolve(response);
1105+
1106+
}, function (error$$1) { return handler(error$$1.response); });
1107+
});
1108+
};
1109+
10691110
/**
10701111
* Base client.
10711112
*/
@@ -1129,7 +1170,7 @@ var Client = function (context) {
11291170

11301171
function sendRequest(request, resolve) {
11311172

1132-
var client = request.client || xhrClient;
1173+
var client = request.client || (inBrowser ? xhrClient : nodeClient);
11331174

11341175
resolve(client(request));
11351176
}
@@ -1303,7 +1344,6 @@ Request.prototype.respondWith = function respondWith (body, options$$1) {
13031344
* Service for sending network requests.
13041345
*/
13051346

1306-
var CUSTOM_HEADERS = {'X-Requested-With': 'XMLHttpRequest'};
13071347
var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'};
13081348
var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'};
13091349

@@ -1338,8 +1378,8 @@ Http.headers = {
13381378
post: JSON_CONTENT_TYPE,
13391379
patch: JSON_CONTENT_TYPE,
13401380
delete: JSON_CONTENT_TYPE,
1341-
custom: CUSTOM_HEADERS,
1342-
common: COMMON_HEADERS
1381+
common: COMMON_HEADERS,
1382+
custom: {}
13431383
};
13441384

13451385
Http.interceptors = [before, method, body, jsonp, header, cors];

0 commit comments

Comments
 (0)