@@ -4,16 +4,65 @@ var util = require('util');
44
55module . exports = function ( options ) {
66 var opts = util . _extend ( {
7- indent : ' '
7+ body : false ,
8+ cert : false ,
9+ headers : false ,
10+ indent : ' ' ,
11+ pretty : false ,
12+ print : false ,
13+ short : false ,
14+ style : false ,
15+ timeout : false ,
16+ verbose : false ,
17+ verify : false
818 } , options ) ;
919
1020 var code = [ ] ;
1121
22+ // start with body pipe
1223 if ( this . source . postData ) {
1324 code . push ( util . format ( 'echo %s | ' , JSON . stringify ( this . source . postData . text ) ) ) ;
1425 }
1526
16- code . push ( util . format ( 'http %s %s%s' , this . source . method , this . source . uriObj . hostname , this . source . uriObj . pathname ) ) ;
27+ var flags = [ ] ;
28+
29+ if ( opts . headers ) {
30+ flags . push ( opts . short ? '-h' : '--headers' ) ;
31+ }
32+
33+ if ( opts . body ) {
34+ flags . push ( opts . short ? '-b' : '--body' ) ;
35+ }
36+
37+ if ( opts . verbose ) {
38+ flags . push ( opts . short ? '-v' : '--verbose' ) ;
39+ }
40+
41+ if ( opts . print ) {
42+ flags . push ( util . format ( '%s=%s' , opts . short ? '-p' : '--print' , opts . print ) ) ;
43+ }
44+
45+ if ( opts . verify ) {
46+ flags . push ( util . format ( '--verify=%s' , opts . verify ) ) ;
47+ }
48+
49+ if ( opts . cert ) {
50+ flags . push ( util . format ( '--cert=%s' , opts . cert ) ) ;
51+ }
52+
53+ if ( opts . pretty ) {
54+ flags . push ( util . format ( '--pretty=%s' , opts . pretty ) ) ;
55+ }
56+
57+ if ( opts . style ) {
58+ flags . push ( util . format ( '--style=%s' , opts . pretty ) ) ;
59+ }
60+
61+ if ( opts . timeout ) {
62+ flags . push ( util . format ( '--timeout=%s' , opts . timeout ) ) ;
63+ }
64+
65+ code . push ( util . format ( 'http %s%s %s' , flags . length ? flags . join ( ' ' ) + ' ' : '' , this . source . method , this . source . url ) ) ;
1766
1867 // construct query params
1968 if ( this . source . queryString && this . source . queryString . length ) {
@@ -22,16 +71,20 @@ module.exports = function (options) {
2271 } ) ;
2372 }
2473
74+ // construct headers
2575 if ( this . source . headers && this . source . headers . length ) {
2676 this . source . headers . map ( function ( header ) {
2777 code . push ( util . format ( '%s:%s' , header . name , header . value ) ) ;
2878 } ) ;
2979 }
3080
31- if ( this . source . headers && this . source . headers . length ) {
32- this . source . headers . map ( function ( header ) {
33- code . push ( util . format ( '%s:%s' , header . name , header . value ) ) ;
81+ // construct cookies argument
82+ if ( this . source . cookies && this . source . cookies . length ) {
83+ var cookies = this . source . cookies . map ( function ( cookie ) {
84+ return encodeURIComponent ( cookie . name ) + '=' + encodeURIComponent ( cookie . value ) ;
3485 } ) ;
86+
87+ code . push ( util . format ( 'Cookie:%s' , cookies . join ( '; ' ) ) ) ;
3588 }
3689
3790 return code . join ( opts . indent !== false ? ' \\\n' + opts . indent : ' ' ) ;
0 commit comments