Skip to content

Commit

Permalink
Bump libcurl from 7.87.0 to 8.0.1 in /api (#2285)
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoku-k authored May 1, 2023
1 parent bf2a7f8 commit 30a0b1c
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 493 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ HomoChecker はホモ([@mpyw](https://twitter.com/mpyw))にリダイレク
### 設定方法

DNS を適切に設定したあと、お使いの Web サーバーに合わせて設定を行います。
HomoChecker は HTTP/1.1、HTTP/2、HTTP/3(Alt-Svc のみ)に対応しています。
HomoChecker は HTTP/1.1、HTTP/2、HTTP/3 に対応しています。

#### Apache

Expand Down
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FROM build-dependencies AS curl
COPY --from=openssl /usr/local/ /usr/local/
COPY --from=nghttp3 /usr/local/ /usr/local/
COPY --from=ngtcp2 /usr/local/ /usr/local/
RUN git clone --depth=1 -b curl-7_87_0 https://github.com/curl/curl && \
RUN git clone --depth=1 -b curl-8_0_1 https://github.com/curl/curl && \
cd curl && \
autoreconf -fi && \
./configure --enable-alt-svc --with-openssl --with-nghttp2 --with-nghttp3 --with-ngtcp2 && \
Expand Down
6 changes: 4 additions & 2 deletions api/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="./vendor/autoload.php" cacheDirectory=".phpunit.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="./vendor/autoload.php" cacheDirectory=".phpunit.cache">
<php>
<const name="CURL_HTTP_VERSION_3" value="30"/>
</php>
Expand All @@ -8,7 +8,7 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory>./src</directory>
</include>
Expand All @@ -17,6 +17,8 @@
<file>./src/index.php</file>
<directory>./src/Providers</directory>
</exclude>
</source>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
Expand Down
21 changes: 0 additions & 21 deletions api/src/Contracts/Repository/AltsvcRepository.php

This file was deleted.

91 changes: 0 additions & 91 deletions api/src/Contracts/Service/Client/Altsvc.php

This file was deleted.

3 changes: 0 additions & 3 deletions api/src/Providers/HomoAppProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
use HomoChecker\Action\HealthCheckAction;
use HomoChecker\Action\ListAction;
use HomoChecker\Action\MetricsAction;
use HomoChecker\Contracts\Repository\AltsvcRepository as AltsvcRepositoryContract;
use HomoChecker\Contracts\Repository\HomoRepository as HomoRepositoryContract;
use HomoChecker\Contracts\Repository\ProfileRepository as ProfileRepositoryContract;
use HomoChecker\Http\NonBufferedBody;
use HomoChecker\Middleware\AccessLogMiddleware;
use HomoChecker\Middleware\ErrorMiddleware;
use HomoChecker\Middleware\MetricsMiddleware;
use HomoChecker\Repository\AltsvcRepository;
use HomoChecker\Repository\HomoRepository;
use HomoChecker\Repository\ProfileRepository;
use Illuminate\Config\Repository;
Expand All @@ -39,7 +37,6 @@ public function register()
$this->app->singleton(ListAction::class);
$this->app->singleton(BadgeAction::class);

$this->app->singleton(AltsvcRepositoryContract::class, AltsvcRepository::class);
$this->app->singleton(HomoRepositoryContract::class, HomoRepository::class);
$this->app->singleton(ProfileRepositoryContract::class, ProfileRepository::class);

Expand Down
31 changes: 0 additions & 31 deletions api/src/Repository/AltsvcRepository.php

This file was deleted.

57 changes: 1 addition & 56 deletions api/src/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,19 @@
use GuzzleHttp\Psr7\Response as Psr7Response;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\TransferStats;
use HomoChecker\Contracts\Repository\AltsvcRepository as AltsvcRepositoryContract;
use HomoChecker\Contracts\Service\Client\Altsvc;
use HomoChecker\Contracts\Service\Client\Response;
use HomoChecker\Contracts\Service\ClientService as ClientServiceContract;
use Illuminate\Support\Collection;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class ClientService implements ClientServiceContract
{
protected ?Collection $altsvc = null;

public function __construct(
protected ClientInterface $client,
protected AltsvcRepositoryContract $altsvcRepository,
protected int $redirect,
) {
}

protected function getAltsvc(string $url): null|string
{
if (!$this->altsvc) {
$this->altsvc = collect($this->altsvcRepository->findAll());
}
return $this->altsvc->where('url', $url)->pluck('protocol')->first();
}

protected function saveAltsvc(string $url, string $protocolId, float $maxAge): void
{
$this->altsvcRepository->save(
$url,
$protocolId,
(new \DateTimeImmutable("{$maxAge} seconds"))->format(\DateTimeInterface::ATOM),
);
}

/**
* Get the responses for URL.
* @param string $url The URL.
Expand All @@ -52,39 +29,7 @@ protected function saveAltsvc(string $url, string $protocolId, float $maxAge): v
public function getAsync(string $url): \Generator
{
for ($i = 0; $i < $this->redirect; ++$i) {
$options = [];

if (str_starts_with($this->getAltsvc($url) ?? '', 'h3')) {
$options['curl'] = [
CURLOPT_CERTINFO => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_3,
];
$options['headers']['Alt-Used'] = parse_url($url, PHP_URL_HOST);
$url = str($url)->replaceFirst('http://', 'https://')->toString();
}

yield $url => $this->client->requestAsync('GET', $url, $options + [
RequestOptions::ON_HEADERS => function (ResponseInterface|\Throwable $response) use ($url) {
if ($response instanceof \Throwable) {
return;
}

$altsvc = $response->getHeaderLine('Alt-Svc');
if (!$altsvc) {
return;
}

/** @var ?Altsvc $h3 */
$h3 = str($altsvc)
->split('/\s*,\s*/')
->mapInto(Altsvc::class)
->first(fn (Altsvc $item) => str_starts_with($item->getProtocolId(), 'h3'));
if (!$h3) {
return;
}

$this->saveAltsvc($url, $h3->getProtocolId(), $h3->getMaxAge());
},
yield $url => $this->client->requestAsync('GET', $url, [
RequestOptions::ON_STATS => function (TransferStats $stats) use (&$result) {
$response = $stats->getResponse();
if (!$response) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
'allow_redirects' => false,
'curl' => [
CURLOPT_CERTINFO => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_3,
],
'headers' => [
'User-Agent' => 'Homozilla/5.0 (Checker/1.14.514; homOSeX 8.10)',
Expand Down
82 changes: 0 additions & 82 deletions api/tests/Case/Repository/AltsvcRepositoryTest.php

This file was deleted.

4 changes: 2 additions & 2 deletions api/tests/Case/Repository/ProfileRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testSave(): void
->with('profiles')
->andReturn($builder);

$altsvc = new ProfileRepository();
$altsvc->save('foo', 'https://img.example.com/foo', '2022-12-31 23:59:59');
$profile = new ProfileRepository();
$profile->save('foo', 'https://img.example.com/foo', '2022-12-31 23:59:59');
}
}
Loading

0 comments on commit 30a0b1c

Please sign in to comment.