Skip to content

Commit 9ac52fd

Browse files
committed
adding utility properties that help implementing new targets
1 parent 561c230 commit 9ac52fd

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/index.js‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var HTTPSnippet = function (req, lang) {
1818
this.source.headers = this.source.headers || [];
1919
this.source.cookies = this.source.cookies || [];
2020
this.source.postData = this.source.postData || {};
21-
this.source.postData.mimeType = this.source.postData.mimeType || 'application/x-www-form-urlencoded';
21+
this.source.postData.mimeType = this.source.postData.mimeType || 'application/octet-stream';
2222

2323
this.source.bodySize = 0;
2424
this.source.headersSize = 0;
@@ -32,6 +32,27 @@ var HTTPSnippet = function (req, lang) {
3232
// construct query string object
3333
this.source.queryObj = {};
3434
this.source.headersObj = {};
35+
this.source.postData.jsonObj = {};
36+
this.source.postData.paramsObj = {};
37+
38+
switch (this.source.postData.mimeType) {
39+
case 'application/x-www-form-urlencoded':
40+
if (!this.source.postData.params) {
41+
this.source.postData.text = '';
42+
} else {
43+
this.source.postData.paramsObj = this.source.postData.params.reduce(reducer, {});
44+
45+
// always overwrite
46+
this.source.postData.text = qs.stringify(this.source.postData.paramsObj);
47+
}
48+
break;
49+
50+
case 'application/json':
51+
if (this.source.postData.text) {
52+
this.source.postData.jsonObj = JSON.parse(this.source.postData.text);
53+
}
54+
break;
55+
}
3556

3657
// construct query objects
3758
if (this.source.queryString && this.source.queryString.length) {

0 commit comments

Comments
 (0)