/** * @param In $inputStream The message input stream * @param MessageInterface $message The message to map the data into * * @throws \Avalonia\Component\Message\Exception\MapperInvalidArgumentException if the given $rawData is not of the good type * @throws \Avalonia\Component\Message\Exception\MapperInvalidDataException if the given $rawData doesn't not fetch the required format * * Maps the given stream into a message */ public function mapStreamToMessage(In $inputStream, MessageInterface $message) { $start = $inputStream->read(strlen(static::HTTP_RESPONSE_STATUS_START)); if (static::HTTP_RESPONSE_STATUS_START === $start) { $statusLine = $start . $this->readHttpLine($inputStream, false); if (0 === preg_match(static::HTTP_RESPONSE_STATUS_PATTERN, $statusLine, $parsedStatusLine)) { throw new HttpMapperInvalidStatusException(sprintf("The HTTP command line is not valid: \"%s. Expected format: HTTP/1.0|1.1 CODE MESSAGE", $statusLine)); } $message->setHeader(HttpMessage::HEADER_HTTP_STATUS_CODE, (int) $parsedStatusLine["code"]); $message->setHeader(HttpMessage::HEADER_HTTP_STATUS_MESSAGE, $parsedStatusLine["message"]); $message->setHeader(HttpMessage::HEADER_HTTP_VERSION, $parsedStatusLine["version"]); // Then read headers and body $this->readHttpHeaderAndBody($inputStream, $message); } else { $message->setHeader(HttpMessage::HEADER_HTTP_VERSION, static::DEFAULT_HTTP_VERSION); $message->setBody($start . $inputStream->readAll()); } }