71 $this->socket->connect();
73 catch (\RuntimeException $e)
78 $this->state = self::CONNECTED;
82 case self::CONNECT_RECEIVED:
83 if ($this->state === self::CONNECTED && $this->useProxy &&
$request->getUri()->getScheme() ===
'https')
88 $this->state = self::CONNECT_SENT;
93 if (
$request->getUri()->getScheme() ===
'https')
95 $this->socket->setBlocking();
97 if ($this->socket->enableCrypto() ===
false)
108 if ($body->isSeekable())
113 $this->state = self::HEADERS_SENT;
117 case self::CONNECT_SENT:
123 $headers = Web\HttpHeaders::createFromString($this->responseHeaders);
125 if (($status = $headers->getStatus()) >= 200 && $status < 300)
127 $this->responseHeaders =
'';
129 $this->state = self::CONNECT_RECEIVED;
133 throw new Http\NetworkException(
$request,
'Error receiving the CONNECT response from the proxy: ' . $headers->getStatus() .
' ' . $headers->getReasonPhrase());
138 case self::HEADERS_SENT:
143 $this->state = self::BODY_SENT;
147 case self::BODY_SENT:
155 $this->response = $this->responseBuilder->createFromString($this->responseHeaders);
166 $this->state = self::HEADERS_RECEIVED;
170 $this->socket->close();
173 $promise->fulfill($this->response);
175 $this->state = self::BODY_RECEIVED;
180 case self::HEADERS_RECEIVED:
185 $this->socket->close();
193 $this->response->adjustHeaders();
196 $promise->fulfill($this->response);
198 $this->state = self::BODY_RECEIVED;
205 $this->socket->close();
207 $promise->reject($exception);
211 $logger->error($exception->getMessage());
293 if (!$body->eof() || $this->requestBodyPart !==
'')
295 if (!$body->eof() && strlen($this->requestBodyPart) < self::BUF_BODY_LEN)
297 $part = $body->read(self::BUF_BODY_LEN);
298 $this->requestBodyPart .= $part;
302 $result = $this->
write($this->requestBodyPart,
'Error sending the message body.');
304 $this->requestBodyPart = substr($this->requestBodyPart, $result);
307 return ($body->eof() && $this->requestBodyPart ===
'');