Skip to content

Commit d62f8e3

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents 530ae10 + 80618fa commit d62f8e3

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/io/files.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
/* globals Request: false */
9+
/* globals Headers: false */
910

1011
'use strict';
1112

@@ -759,12 +760,8 @@ p5.prototype.loadXML = function() {
759760
* in as first argument
760761
*/
761762
p5.prototype.httpGet = function () {
762-
var args = new Array(arguments.length);
763-
args[0] = arguments[0];
764-
args[1] = 'GET';
765-
for (var i = 1; i < arguments.length; ++i) {
766-
args[i+1] = arguments[i];
767-
}
763+
var args = Array.prototype.slice.call(arguments);
764+
args.splice(1, 0, 'GET');
768765
p5.prototype.httpDo.apply(this, args);
769766
};
770767

@@ -785,12 +782,8 @@ p5.prototype.httpGet = function () {
785782
* in as first argument
786783
*/
787784
p5.prototype.httpPost = function () {
788-
var args = new Array(arguments.length);
789-
args[0] = arguments[0];
790-
args[1] = 'POST';
791-
for (var i = 1; i < arguments.length; ++i) {
792-
args[i+1] = arguments[i];
793-
}
785+
var args = Array.prototype.slice.call(arguments);
786+
args.splice(1, 0, 'POST');
794787
p5.prototype.httpDo.apply(this, args);
795788
};
796789

@@ -831,6 +824,7 @@ p5.prototype.httpDo = function () {
831824
var request;
832825
var jsonpOptions = {};
833826
var cbCount = 0;
827+
var contentType = 'text/plain';
834828
// Trim the callbacks off the end to get an idea of how many arguments are passed
835829
for (var i = arguments.length-1; i > 0; i--){
836830
if(typeof arguments[i] === 'function'){
@@ -882,6 +876,7 @@ p5.prototype.httpDo = function () {
882876
}
883877
}else{
884878
data = JSON.stringify(a);
879+
contentType = 'application/json';
885880
}
886881
} else if (typeof a === 'function') {
887882
if (!callback) {
@@ -905,7 +900,10 @@ p5.prototype.httpDo = function () {
905900
request = new Request(path, {
906901
method: method,
907902
mode: 'cors',
908-
body: data
903+
body: data,
904+
headers: new Headers({
905+
'Content-Type': contentType
906+
})
909907
});
910908
}
911909

0 commit comments

Comments
 (0)