@@ -14,6 +14,7 @@ var HTTPSnippet = function (data) {
1414 var entries
1515 var self = this
1616 var input = Object . assign ( { } , data )
17+ var boundary
1718
1819 // prep the main container
1920 self . requests = [ ]
@@ -50,7 +51,29 @@ var HTTPSnippet = function (data) {
5051 } )
5152}
5253
54+ HTTPSnippet . prototype . _generateBoundary = function ( ) {
55+ var self = this
56+ // This generates a 50 character boundary similar to those used by Firefox.
57+ // They are optimized for boyer-moore parsing.
58+ var boundary = '--------------------------' ;
59+ for ( var i = 0 ; i < 24 ; i ++ ) {
60+ boundary += Math . floor ( Math . random ( ) * 10 ) . toString ( 16 ) ;
61+ }
62+
63+ self . _boundary = boundary ;
64+ }
65+
66+ HTTPSnippet . prototype . getBoundary = function ( ) {
67+ var self = this
68+ if ( ! self . _boundary ) {
69+ self . _generateBoundary ( ) ;
70+ }
71+
72+ return self . _boundary ;
73+ }
74+
5375HTTPSnippet . prototype . prepare = function ( request ) {
76+ var self = this
5477 // construct utility properties
5578 request . queryObj = { }
5679 request . headersObj = { }
@@ -105,7 +128,7 @@ HTTPSnippet.prototype.prepare = function (request) {
105128 var form = new MultiPartForm ( )
106129
107130 // easter egg
108- form . _boundary = '---011000010111000001101001'
131+ this . _boundary = '---011000010111000001101001'
109132
110133 request . postData . params . forEach ( function ( param ) {
111134 form . append ( param . name , param . value || '' , {
@@ -114,12 +137,12 @@ HTTPSnippet.prototype.prepare = function (request) {
114137 } )
115138 } )
116139
117- form . pipe ( es . map ( function ( data , cb ) {
118- request . postData . text += data
119- } ) )
140+ // form.pipe(es.map(function (data, cb) {
141+ // request.postData.text += data
142+ // }))
120143
121- request . postData . boundary = form . getBoundary ( )
122- request . headersObj [ 'content-type' ] = 'multipart/form-data; boundary=' + form . getBoundary ( )
144+ request . postData . boundary = this . getBoundary ( )
145+ request . headersObj [ 'content-type' ] = 'multipart/form-data; boundary=' + this . getBoundary ( )
123146 }
124147 break
125148
0 commit comments