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 */
793794p5 . 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 */
819816p5 . 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