File tree Expand file tree Collapse file tree
src/Illuminate/Http/Client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -354,7 +354,7 @@ public function withoutVerifying()
354354 }
355355
356356 /**
357- * Specify where the body of the response will be saved .
357+ * Specify the path where the body of the response should be stored .
358358 *
359359 * @param $to string|resource
360360 * @return $this
@@ -702,25 +702,36 @@ public function buildStubHandler()
702702 $ sink = $ options ['sink ' ] ?? null ;
703703
704704 if ($ sink ) {
705- $ response ->then (function ($ response ) use ($ sink ) {
706- $ body = $ response ->getBody ()->getContents ();
707-
708- if (is_string ($ sink )) {
709- file_put_contents ($ sink , $ body );
710-
711- return ;
712- }
713-
714- fwrite ($ sink , $ body );
715- rewind ($ sink );
716- });
705+ $ response ->then ($ this ->sinkStubHandler ($ sink ));
717706 }
718707
719708 return $ response ;
720709 };
721710 };
722711 }
723712
713+ /**
714+ * Get the sink stub handler callback.
715+ *
716+ * @param string $sink
717+ * @return \Closure
718+ */
719+ protected function sinkStubHandler ($ sink )
720+ {
721+ return function ($ response ) use ($ sink ) {
722+ $ body = $ response ->getBody ()->getContents ();
723+
724+ if (is_string ($ sink )) {
725+ file_put_contents ($ sink , $ body );
726+
727+ return ;
728+ }
729+
730+ fwrite ($ sink , $ body );
731+ rewind ($ sink );
732+ };
733+ }
734+
724735 /**
725736 * Execute the "before sending" callbacks.
726737 *
You can’t perform that action at this time.
0 commit comments