Esempio n. 1
0
 /**
  * @since   2.0.0
  * @test
  */
 public function deleteWritesCorrectRequestWithVersion()
 {
     $this->createHttpRequest()->delete(5, HttpVersion::HTTP_1_0);
     assert($this->memory, equals(Http::lines('DELETE /foo/resource HTTP/1.0', 'Host: example.com', 'X-Binford: 6100', '')));
 }
 /**
  * @since  2.0.0
  * @test
  */
 public function deleteWritesProperHttpRequestLines()
 {
     $this->httpConnection->timeout(2)->asUserAgent('Stubbles HTTP Client')->referedFrom('http://example.com/')->withCookie(['foo' => 'bar baz'])->authorizedAs('user', 'pass')->usingHeader('X-Binford', 6100)->delete();
     assert($this->memory, equals(Http::lines('DELETE /foo/resource HTTP/1.1', 'Host: example.com', 'User-Agent: Stubbles HTTP Client', 'Referer: http://example.com/', 'Cookie: foo=bar+baz;', 'Authorization: BASIC ' . base64_encode('user:pass'), 'X-Binford: 6100', '')));
 }
 /**
  * @test
  * @dataProvider  responseInstanceMethods
  * @since  4.0.0
  */
 public function statusLineWithInvalidHttpVersionLeadsToProtocolViolation($method)
 {
     $httpResponse = $this->createResponse(Http::lines('HTTP/400 102 Processing', 'Host: localhost', ''));
     expect(function () use($httpResponse, $method) {
         $httpResponse->{$method}();
     })->throws(ProtocolViolation::class)->withMessage('Received status line "HTTP/400 102 Processing" does not match' . ' expected format "=^(HTTP/\\d+\\.\\d+) (\\d{3}) ([^\\r]*)="');
 }
Esempio n. 4
0
 /**
  * @test
  * @since  8.0.0
  */
 public function invalidRfcsAreInvalid()
 {
     assertFalse(Http::isValidRfc('RFC 0815'));
 }
Esempio n. 5
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());
 }