Skip to content

Commit 80618fa

Browse files
authored
Merge pull request #1900 from limzykenneth/master
Fix missing content type headers
2 parents 3d56c74 + 714e3e6 commit 80618fa

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

@@ -791,12 +792,8 @@ p5.prototype.selectInput = function () {
791792
* in as first argument
792793
*/
793794
p5.prototype.httpGet = function () {
794-
var args = new Array(arguments.length);
795-
args[0] = arguments[0];
796-
args[1] = 'GET';
797-
for (var i = 1; i < arguments.length; ++i) {
798-
args[i+1] = arguments[i];
799-
}
795+
var args = Array.prototype.slice.call(arguments);
796+
args.splice(1, 0, 'GET');
800797
p5.prototype.httpDo.apply(this, args);
801798
};
802799

@@ -817,12 +814,8 @@ p5.prototype.httpGet = function () {
817814
* in as first argument
818815
*/
819816
p5.prototype.httpPost = function () {
820-
var args = new Array(arguments.length);
821-
args[0] = arguments[0];
822-
args[1] = 'POST';
823-
for (var i = 1; i < arguments.length; ++i) {
824-
args[i+1] = arguments[i];
825-
}
817+
var args = Array.prototype.slice.call(arguments);
818+
args.splice(1, 0, 'POST');
826819
p5.prototype.httpDo.apply(this, args);
827820
};
828821

@@ -863,6 +856,7 @@ p5.prototype.httpDo = function () {
863856
var request;
864857
var jsonpOptions = {};
865858
var cbCount = 0;
859+
var contentType = 'text/plain';
866860
// Trim the callbacks off the end to get an idea of how many arguments are passed
867861
for (var i = arguments.length-1; i > 0; i--){
868862
if(typeof arguments[i] === 'function'){
@@ -914,6 +908,7 @@ p5.prototype.httpDo = function () {
914908
}
915909
}else{
916910
data = JSON.stringify(a);
911+
contentType = 'application/json';
917912
}
918913
} else if (typeof a === 'function') {
919914
if (!callback) {
@@ -937,7 +932,10 @@ p5.prototype.httpDo = function () {
937932
request = new Request(path, {
938933
method: method,
939934
mode: 'cors',
940-
body: data
935+
body: data,
936+
headers: new Headers({
937+
'Content-Type': contentType
938+
})
941939
});
942940
}
943941

0 commit comments

Comments
 (0)