1
1
var Stream = require ( 'stream' ) ;
2
2
var Response = require ( './response' ) ;
3
- var concatStream = require ( 'concat-stream' ) ;
4
3
var Base64 = require ( 'Base64' ) ;
5
4
var util = require ( 'util' ) ;
6
5
7
6
var Request = module . exports = function ( xhr , params ) {
8
7
var self = this ;
9
8
self . writable = true ;
10
9
self . xhr = xhr ;
11
- self . body = concatStream ( )
10
+ self . body = [ ] ;
12
11
13
12
self . uri = ( params . scheme || 'http' ) + '://'
14
13
+ params . host
@@ -72,7 +71,7 @@ Request.prototype.setHeader = function (key, value) {
72
71
} ;
73
72
74
73
Request . prototype . write = function ( s ) {
75
- this . body . write ( s ) ;
74
+ this . body . push ( s ) ;
76
75
} ;
77
76
78
77
Request . prototype . destroy = function ( s ) {
@@ -81,9 +80,27 @@ Request.prototype.destroy = function (s) {
81
80
} ;
82
81
83
82
Request . prototype . end = function ( s ) {
84
- if ( s !== undefined ) this . body . write ( s ) ;
85
- this . body . end ( )
86
- this . xhr . send ( this . body . getBody ( ) ) ;
83
+ if ( s !== undefined ) this . body . push ( s ) ;
84
+ if ( this . body . length === 0 ) {
85
+ this . xhr . send ( '' ) ;
86
+ }
87
+ else if ( typeof this . body [ 0 ] === 'string' ) {
88
+ this . xhr . send ( this . body . join ( '' ) ) ;
89
+ }
90
+ else if ( isArray ( this . body [ 0 ] ) ) {
91
+ var body = [ ] ;
92
+ for ( var i = 0 ; i < this . body . length ; i ++ ) {
93
+ body . push . apply ( body , this . body [ i ] ) ;
94
+ }
95
+ this . xhr . send ( body ) ;
96
+ }
97
+ else {
98
+ var body = '' ;
99
+ for ( var i = 0 ; i < this . body . length ; i ++ ) {
100
+ body += this . body [ i ] . toString ( ) ;
101
+ }
102
+ this . xhr . send ( body ) ;
103
+ }
87
104
} ;
88
105
89
106
// Taken from http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html
0 commit comments