This repository was archived by the owner on Nov 7, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111'use strict'
1212
1313var util = require ( 'util' )
14+ var helpers = require ( './helpers' )
1415var CodeBuilder = require ( '../../helpers/code-builder' )
1516
1617module . exports = function ( source , options ) {
@@ -67,9 +68,13 @@ module.exports = function (source, options) {
6768 name : 'CURLOPT_CUSTOMREQUEST' ,
6869 value : source . method
6970 } , {
70- escape : true ,
71+ escape : ! source . postData . jsonObj ,
7172 name : 'CURLOPT_POSTFIELDS' ,
72- value : source . postData ? source . postData . text : undefined
73+ value : source . postData ? (
74+ source . postData . jsonObj ?
75+ 'json_encode(' + helpers . convert ( source . postData . jsonObj , opts . indent ) + ')' :
76+ source . postData . text
77+ ) : undefined
7378 } ]
7479
7580 code . push ( 'curl_setopt_array($curl, array(' )
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ module.exports = function (source, options) {
6666 . blank ( )
6767 break
6868
69+ case 'application/json' :
70+ code . push ( '$request->setContentType(%s);' , helpers . convert ( source . postData . mimeType ) )
71+ . push ( '$request->setBody(json_encode(%s));' , helpers . convert ( source . postData . paramsObj , opts . indent ) )
72+ . blank ( )
73+ break
74+
6975 default :
7076 if ( source . postData . text ) {
7177 code . push ( '$request->setBody(%s);' , helpers . convert ( source . postData . text ) )
Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ module.exports = function (source, options) {
7575 hasBody = true
7676 break
7777
78+ case 'application/json' :
79+ code . push ( '$body = new http\\Message\\Body;' )
80+ . push ( '$body->append(json_encode(%s));' , helpers . convert ( source . postData . jsonObj , opts . indent ) )
81+ break ;
7882 default :
7983 if ( source . postData . text ) {
8084 code . push ( '$body = new http\\Message\\Body;' )
You can’t perform that action at this time.
0 commit comments