33namespace React \Http \Client ;
44
55use Evenement \EventEmitter ;
6- use Guzzle \Http \Url ;
7- use React \Stream \Stream ;
86use Guzzle \Http \Message \Request as GuzzleRequest ;
9- use React \Http \Client \Response ;
10- use React \EventLoop \LoopInterface ;
7+ use Guzzle \Http \Url ;
118use Guzzle \Parser \Message \MessageParser ;
9+ use React \EventLoop \LoopInterface ;
1210use React \Http \Client \ConnectionManagerInterface ;
11+ use React \Http \Client \Response ;
1312use React \Http \Client \ResponseHeaderParser ;
13+ use React \Stream \Stream ;
1414use React \Stream \WritableStreamInterface ;
1515
1616class Request extends EventEmitter implements WritableStreamInterface
1717{
18-
1918 const STATE_INIT = 0 ;
2019 const STATE_WRITING_HEAD = 1 ;
2120 const STATE_HEAD_WRITTEN = 2 ;
@@ -45,7 +44,7 @@ public function isWritable()
4544 public function writeHead ()
4645 {
4746 if (self ::STATE_WRITING_HEAD <= $ this ->state ) {
48- throw new \LogicException ('headers already written ' );
47+ throw new \LogicException ('Headers already written ' );
4948 }
5049
5150 $ this ->state = self ::STATE_WRITING_HEAD ;
@@ -55,10 +54,10 @@ public function writeHead()
5554 $ streamRef = &$ this ->stream ;
5655 $ stateRef = &$ this ->state ;
5756
58- $ this ->connect (function ($ stream , \Exception $ error = null ) use ($ that , $ request , &$ streamRef , &$ stateRef ) {
57+ $ this ->connect (function ($ stream , \Exception $ error = null ) use ($ that , $ request , &$ streamRef , &$ stateRef ) {
5958 if (!$ stream ) {
6059 $ that ->closeError (new \RuntimeException (
61- "connection failed " ,
60+ "Connection failed " ,
6261 0 ,
6362 $ error
6463 ));
@@ -93,7 +92,7 @@ public function write($data)
9392 return $ this ->stream ->write ($ data );
9493 }
9594
96- $ this ->on ('headers-written ' , function ($ that ) use ($ data ) {
95+ $ this ->on ('headers-written ' , function ($ that ) use ($ data ) {
9796 $ that ->write ($ data );
9897 });
9998
@@ -127,8 +126,7 @@ public function handleData($data)
127126 $ this ->buffer .= $ data ;
128127
129128 if (false !== strpos ($ this ->buffer , "\r\n\r\n" )) {
130-
131- list ($ response , $ body ) = $ this ->parseResponse ($ this ->buffer );
129+ list ($ response , $ bodyChunk ) = $ this ->parseResponse ($ this ->buffer );
132130
133131 $ this ->stream ->removeListener ('drain ' , array ($ this , 'handleDrain ' ));
134132 $ this ->stream ->removeListener ('data ' , array ($ this , 'handleData ' ));
@@ -138,34 +136,34 @@ public function handleData($data)
138136 $ this ->response = $ response ;
139137 $ that = $ this ;
140138
141- $ response ->on ('end ' , function () use ($ that ) {
139+ $ response ->on ('end ' , function () use ($ that ) {
142140 $ that ->close ();
143141 });
144- $ response ->on ('error ' , function (\Exception $ error ) use ($ that ) {
142+ $ response ->on ('error ' , function (\Exception $ error ) use ($ that ) {
145143 $ that ->closeError (new \RuntimeException (
146- "response error " ,
144+ "An error occured in the response " ,
147145 0 ,
148146 $ error
149147 ));
150148 });
151149
152150 $ this ->emit ('response ' , array ($ response , $ this ));
153151
154- $ response ->emit ('data ' , array ($ body ));
152+ $ response ->emit ('data ' , array ($ bodyChunk ));
155153 }
156154 }
157155
158156 public function handleEnd ()
159157 {
160158 $ this ->closeError (new \RuntimeException (
161- "connection closed before receiving response "
159+ "Connection closed before receiving response "
162160 ));
163161 }
164162
165163 public function handleError ($ error )
166164 {
167165 $ this ->closeError (new \RuntimeException (
168- "stream error " ,
166+ "An error occurred in the underlying stream " ,
169167 0 ,
170168 $ error
171169 ));
@@ -220,7 +218,7 @@ protected function connect($callback)
220218 $ connectionManager = $ this ->connectionManager ;
221219 $ that = $ this ;
222220
223- $ connectionManager ->getConnection (function ($ stream ) use ($ that , $ callback ) {
221+ $ connectionManager ->getConnection (function ($ stream ) use ($ that , $ callback ) {
224222 call_user_func ($ callback , $ stream );
225223 }, $ host , $ port );
226224 }
@@ -233,7 +231,6 @@ public function setResponseFactory($factory)
233231 public function getResponseFactory ()
234232 {
235233 if (null === $ factory = $ this ->responseFactory ) {
236-
237234 $ loop = $ this ->loop ;
238235 $ stream = $ this ->stream ;
239236
0 commit comments