Skip to content

Commit

Permalink
Change namespace to Amp\Http\Client
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed May 30, 2019
1 parent f6422cc commit 862817e
Show file tree
Hide file tree
Showing 40 changed files with 475 additions and 394 deletions.
45 changes: 0 additions & 45 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
},
"autoload": {
"psr-4": {
"Amp\\Artax\\": "lib"
"Amp\\Http\\Client\\": "lib"
}
},
"autoload-dev": {
"psr-4": {
"Amp\\Test\\Artax\\": "test"
"Amp\\Http\\Client\\": "test"
}
}
}
20 changes: 10 additions & 10 deletions lib/Client.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Amp\Artax;
namespace Amp\Http\Client;

use Amp\Artax\Internal\Parser;
use Amp\Http\Client\Internal\Parser;
use Amp\CancellationToken;
use Amp\Promise;

Expand All @@ -12,28 +12,28 @@
interface Client
{
/** Whether to automatically apply compression to requests and responses. */
const OP_AUTO_ENCODING = 'amp.artax.client.auto-encoding';
public const OP_AUTO_ENCODING = 'amp.artax.client.auto-encoding';

/** Transfer timeout in milliseconds until an HTTP request is automatically aborted, use 0 to disable. */
const OP_TRANSFER_TIMEOUT = 'amp.artax.client.transfer-timeout';
public const OP_TRANSFER_TIMEOUT = 'amp.artax.client.transfer-timeout';

/** How many redirects to follow, might be 0 to not follow any redirects. */
const OP_MAX_REDIRECTS = 'amp.artax.client.max-redirects';
public const OP_MAX_REDIRECTS = 'amp.artax.client.max-redirects';

/** Whether to automatically add a "Referer" header on redirects. */
const OP_AUTO_REFERER = 'amp.artax.client.auto-referer';
public const OP_AUTO_REFERER = 'amp.artax.client.auto-referer';

/** Whether to directly discard the HTTP response body or not. */
const OP_DISCARD_BODY = 'amp.artax.client.discard-body';
public const OP_DISCARD_BODY = 'amp.artax.client.discard-body';

/** Default headers to use. */
const OP_DEFAULT_HEADERS = 'amp.artax.client.default-headers';
public const OP_DEFAULT_HEADERS = 'amp.artax.client.default-headers';

/** Maximum header size, usually doesn't have to be adjusted. */
const OP_MAX_HEADER_BYTES = Parser::OP_MAX_HEADER_BYTES;
public const OP_MAX_HEADER_BYTES = Parser::OP_MAX_HEADER_BYTES;

/** Maximum body size. Needs to be adjusted for streaming large responses, e.g. Streaming APIs. */
const OP_MAX_BODY_BYTES = Parser::OP_MAX_BODY_BYTES;
public const OP_MAX_BODY_BYTES = Parser::OP_MAX_BODY_BYTES;

/**
* Asynchronously request an HTTP resource.
Expand Down
15 changes: 3 additions & 12 deletions lib/ConnectionInfo.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
<?php

namespace Amp\Artax;
namespace Amp\Http\Client;

final class ConnectionInfo
{
private $localAddress;
private $remoteAddress;
private $tlsInfo;

public function __construct(string $localAddress, string $remoteAddress, TlsInfo $tlsInfo = null)
public function __construct(string $localAddress, string $remoteAddress, ?TlsInfo $tlsInfo = null)
{
$this->localAddress = $localAddress;
$this->remoteAddress = $remoteAddress;
$this->tlsInfo = $tlsInfo;
}

/**
* @return string
*/
public function getLocalAddress(): string
{
return $this->localAddress;
}

/**
* @return string
*/
public function getRemoteAddress(): string
{
return $this->remoteAddress;
}

/**
* @return TlsInfo|null
*/
public function getTlsInfo()
public function getTlsInfo(): ?TlsInfo
{
return $this->tlsInfo;
}
Expand Down
21 changes: 14 additions & 7 deletions lib/Cookie/ArrayCookieJar.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Amp\Artax\Cookie;
namespace Amp\Http\Client\Cookie;

class ArrayCookieJar implements CookieJar
{
Expand All @@ -13,7 +13,7 @@ class ArrayCookieJar implements CookieJar
*
* @return void
*/
public function store(Cookie $cookie)
public function store(Cookie $cookie): void
{
$this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
}
Expand All @@ -23,15 +23,15 @@ public function store(Cookie $cookie)
*
* @param Cookie $cookie
*/
public function remove(Cookie $cookie)
public function remove(Cookie $cookie): void
{
unset($this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()]);
}

/**
* Remove all stored cookies.
*/
public function removeAll()
public function removeAll(): void
{
$this->cookies = [];
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function get(string $domain, string $path = '', string $name = null): arr
return $matches;
}

private function clearExpiredCookies()
private function clearExpiredCookies(): void
{
foreach ($this->cookies as $domain => $domainCookies) {
foreach ($domainCookies as $path => $pathCookies) {
Expand Down Expand Up @@ -113,7 +113,9 @@ private function matchesDomain(string $requestDomain, string $cookieDomain): boo
return true;
}

if (!($isWildcardCookieDomain = ($cookieDomain[0] === '.'))) {
/** @noinspection SubStrUsedAsStrPosInspection */
$isWildcardCookieDomain = $cookieDomain[0] === '.';
if (!$isWildcardCookieDomain) {
return false;
}

Expand All @@ -130,8 +132,13 @@ private function matchesDomain(string $requestDomain, string $cookieDomain): boo

/**
* @link http://tools.ietf.org/html/rfc6265#section-5.1.4
*
* @param $requestPath
* @param $cookiePath
*
* @return bool
*/
private function matchesPath($requestPath, $cookiePath)
private function matchesPath($requestPath, $cookiePath): bool
{
if ($requestPath === $cookiePath) {
$isMatch = true;
Expand Down
Loading

0 comments on commit 862817e

Please sign in to comment.