Skip to content

Commit

Permalink
1. User a human-readable header parser error message when user wants …
Browse files Browse the repository at this point in the history
…to use a `:` character in header values.

2. Fixed image building for M1 processor
3. Add a normal compatibility with PHP 8.1
  • Loading branch information
roquie committed Sep 6, 2022
1 parent 30073fd commit 225629e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ None.
### Fixed

* Fixes prerender host proxy (add nginx option `proxy_ssl_server_name on`).
* User a human-readable header parser error message when user wants to use a `:` character in header values.

## [4.0.0] - 2020-01-03

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM composer/composer:2 AS deps
FROM --platform=amd64 composer/composer:2 AS deps

COPY . /app

RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs

FROM spacetabio/box-php:1.0.0 AS build
FROM --platform=amd64 spacetabio/box-php:1.1.0 AS build

WORKDIR /app
COPY --from=deps /app /app
RUN box compile

FROM php:8.1-cli-alpine
FROM --platform=amd64 php:8.1-cli-alpine

ENV NGINX_VERSION 1.21.1
ENV NGX_BROTLI_COMMIT 9aec15e2aa6feea2113119ba06460af70ab3ea62
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FILE = Dockerfile

image:
sed "s/{{ version }}/$(VERSION)/g" $(FILE) > /tmp/$(FILE)
docker build -f /tmp/$(FILE) -t $(IMAGE):$(VERSION) .
docker build --platform linux/amd64 -f /tmp/$(FILE) -t $(IMAGE):$(VERSION) .

push:
docker push $(IMAGE):$(VERSION)
Expand All @@ -17,13 +17,13 @@ test:
$(IMAGE):4.1.0-xdebug -c "vendor/bin/phpunit"

image_test:
docker build -t $(IMAGE):4.1.0-xdebug -f test.dockerfile .
docker build --platform linux/amd64 -t $(IMAGE):4.1.0-xdebug -f test.dockerfile .

push_test:
docker push $(IMAGE):4.1.0-xdebug

image_box:
docker build -t spacetabio/box-php:1.0.0 -f box.dockerfile .
docker build --platform linux/amd64 -t spacetabio/box-php:1.1.0 -f box.dockerfile .

push_box:
docker push spacetabio/box-php:1.0.0
docker push spacetabio/box-php:1.1.0
4 changes: 2 additions & 2 deletions box.dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM php:8.0-cli-alpine
FROM --platform=amd64 php:8.1-cli-alpine

RUN wget https://github.com/box-project/box/releases/download/3.11.1/box.phar \
RUN wget https://github.com/box-project/box/releases/download/4.0.2/box.phar \
&& mv box.phar /usr/local/bin/box \
&& chmod +x /usr/local/bin/box

Expand Down
12 changes: 9 additions & 3 deletions src/Header/ConvertsHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Spacetab\Server\Header;

use InvalidArgumentException;
use Spacetab\Configuration\ConfigurationInterface;
use Spacetab\Server\Exception\HeaderException;
use Throwable;

final class ConvertsHeader implements HeaderInterface
{
Expand Down Expand Up @@ -42,7 +44,11 @@ public function convert(): array

// Backward compatibility.
if (!isset($values[0]['value'])) {
$results[$item] = join('; ', (array) $values);
try {
$results[$item] = implode('; ', (array) $values);
} catch (Throwable) {
throw new InvalidArgumentException('Headers parse error. Check : symbol or indentation (use "" for escaping :).');
}
}

// Checks new extended format for sent headers from yaml values.
Expand All @@ -53,10 +59,10 @@ public function convert(): array
throw HeaderException::invalidHeaderFormat();
}

$array[] = join('; ', (array) $value['value']);
$array[] = implode('; ', (array) $value['value']);
}

$results[$item] = join(', ', $array);
$results[$item] = implode(', ', $array);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test.dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM composer/composer:2 AS deps
FROM --platform=amd64 composer/composer:2 AS deps

COPY . /app

RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs

FROM spacetabio/box-php:1.0.0 AS build
FROM --platform=amd64 spacetabio/box-php:1.0.0 AS build

WORKDIR /app
COPY --from=deps /app /app
RUN box compile

FROM php:8.1-cli-alpine
FROM --platform=amd64 php:8.1-cli-alpine

ENV NGINX_VERSION 1.21.1
ENV NGX_BROTLI_COMMIT 9aec15e2aa6feea2113119ba06460af70ab3ea62
Expand Down
12 changes: 12 additions & 0 deletions tests/Header/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Spacetab\Tests\Server\Header;

use InvalidArgumentException;
use Spacetab\Configuration\Configuration;
use Spacetab\Server\Exception\HeaderException;
use Spacetab\Server\Header\ConvertsHeader;
Expand Down Expand Up @@ -50,4 +51,15 @@ public function testHowInvalidHeaderValueCheckWorks()
$h = new ConvertsHeader($conf);
$h->convert();
}

public function testInvalidToStringConversionWhenHeadersParsed()
{
$conf = new Configuration(__DIR__ . '/../configuration', 'headers_warning');
$conf->load();

$this->expectException(InvalidArgumentException::class);

$h = new ConvertsHeader($conf);
$h->convert();
}
}
7 changes: 7 additions & 0 deletions tests/configuration/headers_warning/server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
headers_warning:
server:
headers:
contentSecurityPolicy:
- "default-src 'self' data": 'https://*.teaworkshop.ru *.cdek.ru pickpoint.ru api-maps.yandex.ru maps.yandex.net https://*.jivosite.com https://*.dadata.ru sentry.io *.yandex.ru *.vk.com *.googletagmanager.com *.google-analytics.com https://*.facebook.net https://*.facebook.com'
port: 8081
root: ./tests/example_dist/simple
4 changes: 2 additions & 2 deletions tests/example_dist/head_link_not_exists/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" name="viewport">
<meta content="ie=edge" http-equiv="X-UA-Compatible">
<title>Document</title>
<link rel="preload" href="/__config.js" as="script"></head>
<link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"></head>
<body>
hello stranger!
<script src="/__config.js"></script><script>
<script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script>

</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions tests/example_dist/vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="icon" href="/favicon.ico">
<link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="preload" href="/__config.js" as="script"><link rel="icon" href="/favicon.ico">
<title>example_dist</title>
<link href="/js/about.5273d30c.js" rel="prefetch">
<link href="/css/app.e28d37a7.css" rel="preload" as="style">
Expand All @@ -16,7 +16,7 @@
<noscript><strong>We're sorry but example_dist doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong></noscript>
<div id="app"></div>
<script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/js/chunk-vendors.a377004b.js"></script>
<script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/__config.js"></script><script src="/js/chunk-vendors.a377004b.js"></script>
<script src="/js/app.06433c76.js"></script>
</body>
</html>

0 comments on commit 225629e

Please sign in to comment.