40 static $normalize = array(
"\r",
"\n");
41 $length = strlen($header);
42 $header = str_replace($normalize,
'', $header);
44 if (strpos($header,
'HTTP/') === 0) {
46 $startLine = explode(
' ', $header, 3);
47 $code = $startLine[1];
48 $status = isset($startLine[2]) ? $startLine[2] :
'';
52 if ($code >= 200 && $code < 300) {
53 $body = $this->request->getResponseBody();
58 $response =
new Response($code,
null, $body);
59 $response->setStatus($code, $status);
60 $this->request->startResponse($response);
62 $this->request->dispatch(
'request.receive.status_line', array(
65 'status_code' => $code,
66 'reason_phrase' => $status
69 } elseif ($pos = strpos($header,
':')) {
70 $this->request->getResponse()->addHeader(
71 trim(substr($header, 0, $pos)),
72 trim(substr($header, $pos + 1))
88 public function progress($downloadSize, $downloaded, $uploadSize, $uploaded, $handle =
null)
90 $this->request->dispatch(
'curl.callback.progress', array(
91 'request' => $this->request,
93 'download_size' => $downloadSize,
94 'downloaded' => $downloaded,
95 'upload_size' => $uploadSize,
96 'uploaded' => $uploaded
111 $this->request->dispatch(
'curl.callback.write', array(
112 'request' => $this->request,
117 if ($response = $this->request->getResponse()) {
118 return $response->getBody()->write($write);
136 if (!($body = $this->request->getBody())) {
140 $read = (string) $body->read($length);
142 $this->request->dispatch(
'curl.callback.read', array(
'request' => $this->request,
'read' => $read));