/**
  * @test
  */
 public function castFromStringReturnsInstance()
 {
     assert(HttpVersion::castFrom('HTTP/1.1'), equals(new HttpVersion(1, 1)));
 }
Example #2
0
 /**
  * helper method to send the headers
  *
  * @param   \stubbles\peer\Stream                   $socket      output stream to write request to
  * @param   string                                  $method   http method
  * @param   string|\stubbles\peer\http\HttpVersion  $version  http version
  * @throws  \InvalidArgumentException
  */
 private function processHeader(Stream $socket, string $method, $version)
 {
     $version = HttpVersion::castFrom($version);
     if (!$version->equals(HttpVersion::HTTP_1_0) && !$version->equals(HttpVersion::HTTP_1_1)) {
         throw new \InvalidArgumentException('Invalid HTTP version ' . $version . ', please use either ' . HttpVersion::HTTP_1_0 . ' or ' . HttpVersion::HTTP_1_1);
     }
     $path = $this->httpUri->path();
     if ($this->httpUri->hasQueryString() && $this->methodAllowsQueryString($method)) {
         $path .= '?' . $this->httpUri->queryString();
     }
     $socket->write(Http::line($method . ' ' . $path . ' ' . $version));
     $socket->write(Http::line('Host: ' . $this->httpUri->hostname()));
     foreach ($this->headers as $key => $value) {
         $socket->write(Http::line($key . ': ' . $value));
     }
     $socket->write(Http::emptyLine());
 }