├── .gitignore
├── docker-compose
├── html
│ ├── .gitignore
│ ├── composer.json
│ ├── index.php
│ └── composer.lock
└── docker-compose.yml
├── runtests.sh
├── src
└── Traefik
│ ├── Middleware
│ ├── MiddlewareInterface.php
│ ├── Config
│ │ ├── MiddlewareInterface.php
│ │ ├── AddPrefix.php
│ │ ├── ReplacePath.php
│ │ ├── Chain.php
│ │ ├── ContentType.php
│ │ ├── CircuitBreaker.php
│ │ ├── Retry.php
│ │ ├── Compress.php
│ │ ├── StripPrefixRegex.php
│ │ ├── ReplacePathRegex.php
│ │ ├── StripPrefix.php
│ │ ├── InFlightReq.php
│ │ ├── RateLimit.php
│ │ ├── ErrorPage.php
│ │ ├── RedirectScheme.php
│ │ ├── RedirectRegex.php
│ │ ├── IpWhiteList.php
│ │ ├── ForwardAuth.php
│ │ ├── Buffering.php
│ │ ├── SourceCriterion.php
│ │ ├── BasicAuth.php
│ │ ├── Tls.php
│ │ ├── DigestAuth.php
│ │ ├── PassTLSClientCert.php
│ │ ├── Certificate.php
│ │ └── Headers.php
│ ├── Exception
│ │ └── Duplicate.php
│ ├── Retry.php
│ ├── Chain.php
│ ├── AddPrefix.php
│ ├── CircuitBreaker.php
│ ├── ReplacePath.php
│ ├── ContentType.php
│ ├── Compress.php
│ ├── StripPrefixRegex.php
│ ├── StripPrefix.php
│ ├── InFlightReq.php
│ ├── ReplacePathRegex.php
│ ├── ErrorPage.php
│ ├── RedirectRegex.php
│ ├── RedirectScheme.php
│ ├── RateLimit.php
│ ├── IpWhiteList.php
│ ├── ForwardAuth.php
│ ├── DigestAuth.php
│ ├── BasicAuth.php
│ ├── MiddlewareAbstract.php
│ ├── Buffering.php
│ ├── PassTLSClientCert.php
│ └── Headers.php
│ ├── Tcp
│ ├── Server.php
│ ├── Router.php
│ └── Service.php
│ ├── Type
│ ├── RouterTrait.php
│ ├── ServiceTrait.php
│ └── MiddlewareTrait.php
│ ├── Transport
│ ├── HttpTrait.php
│ ├── TcpTrait.php
│ └── UdpTrait.php
│ ├── ConfigObject.php
│ ├── Http
│ ├── Server.php
│ ├── Router.php
│ ├── Middleware.php
│ └── Service.php
│ ├── Udp
│ ├── Server.php
│ ├── Router.php
│ └── Service.php
│ ├── Service
│ └── AbstractObject.php
│ ├── RouterObject.php
│ └── Config.php
├── tests
├── bootstrap.php
├── tcp
│ ├── TcpServiceTest.php
│ └── TcpRouterTest.php
├── udp
│ ├── UdpServiceTest.php
│ └── UdpRouterTest.php
├── http
│ ├── HttpServiceTest.php
│ ├── HttpRouterTest.php
│ └── HttpMiddlewareTest.php
└── config
│ ├── fullConfig.json
│ ├── fullConfig copy.json
│ └── fullConfigTest.php
├── composer.json
├── .editorconfig
├── .gitlab-ci.yml
└── README.MD
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | /.idea
3 |
--------------------------------------------------------------------------------
/docker-compose/html/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | /acme
3 |
--------------------------------------------------------------------------------
/runtests.sh:
--------------------------------------------------------------------------------
1 | ./vendor/bin/phpunit --testdox tests
2 |
--------------------------------------------------------------------------------
/docker-compose/html/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "stormbyte/traefik-http-config": "^0.2"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/MiddlewareInterface.php:
--------------------------------------------------------------------------------
1 | address = $address;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Traefik/Type/RouterTrait.php:
--------------------------------------------------------------------------------
1 | url = $url;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/MiddlewareInterface.php:
--------------------------------------------------------------------------------
1 | address = $address;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | prefix ?? null;
11 | }
12 |
13 | public function setPrefix(string $prefix): self {
14 | $this->prefix = $prefix;
15 | return $this;
16 | }
17 |
18 | public function getMiddlewareClassName(): string {
19 | return \Traefik\Middleware\AddPrefix::class;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Retry.php:
--------------------------------------------------------------------------------
1 | getAttempts()) {
17 | $this->middlewareData['attempts'] = $attempts;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Chain.php:
--------------------------------------------------------------------------------
1 | getMiddlewares()) {
16 | $this->middlewareData['middlewares'] = $middlewares;
17 | }
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/AddPrefix.php:
--------------------------------------------------------------------------------
1 | getPrefix()) {
16 | $this->middlewareData['prefix'] = $prefix;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/CircuitBreaker.php:
--------------------------------------------------------------------------------
1 | getExpression()) {
15 | $this->middlewareData['expression'] = $expression;
16 | }
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/ReplacePath.php:
--------------------------------------------------------------------------------
1 | getPath()) {
17 | $this->middlewareData['path'] = $path;
18 | }
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/ContentType.php:
--------------------------------------------------------------------------------
1 | getAutoDetect())) {
16 | $this->middlewareData['autoDetect'] = $config->getAutoDetect();
17 | }
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Compress.php:
--------------------------------------------------------------------------------
1 | getExcludedContentTypes()) {
16 | $this->middlewareData['excludedContentTypes'] = $excludedContentTypes;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/StripPrefixRegex.php:
--------------------------------------------------------------------------------
1 | getRegex()) {
17 | $this->middlewareData['regex'] = $prefixes;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "stormbyte/traefik-http-config",
3 | "type": "library",
4 | "description": "A library to generate a Http Provider for Traefik",
5 | "keywords": ["traefik","http","config","php"],
6 | "homepage": "http://stormbyte.nl",
7 | "license": "MIT",
8 | "minimum-stability": "dev",
9 | "authors": [
10 | {
11 | "name": "N.A. Walhof",
12 | "homepage": "http://stormbyte.nl"
13 | }
14 | ],
15 | "autoload": {
16 | "psr-4": {
17 | "Traefik\\": "src/Traefik"
18 | }
19 | },
20 | "require-dev": {
21 | "phpunit/phpunit": "^9"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/ReplacePath.php:
--------------------------------------------------------------------------------
1 | path ?? null;
21 | }
22 |
23 | /**
24 | * @param string $path
25 | * @return $this
26 | */
27 | public function setPath(string $path): self {
28 | $this->path = $path;
29 | return $this;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/StripPrefix.php:
--------------------------------------------------------------------------------
1 | getForceSlash() ) ) {
17 | $this->middlewareData['forceSlash'] = $config->getForceSlash();
18 | }
19 |
20 | if ($prefixes = $config->getPrefixes()) {
21 | $this->middlewareData['prefixes'] = $prefixes;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Chain.php:
--------------------------------------------------------------------------------
1 | middlewares ?? null;
21 | }
22 |
23 | /**
24 | * @param string $middleware
25 | * @return $this
26 | */
27 | public function addMiddleware(string $middleware): self {
28 | $this->middlewares[] = $middleware;
29 | return $this;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/InFlightReq.php:
--------------------------------------------------------------------------------
1 | getAmount()) {
17 | $this->middlewareData['amount'] = $amount;
18 | }
19 | if ($sourceCriterion = $config->getSourceCriterion()) {
20 | $this->middlewareData['sourceCriterion'] = $sourceCriterion->getData();
21 | }
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/ContentType.php:
--------------------------------------------------------------------------------
1 | autoDetect ?? null;
21 | }
22 |
23 | /**
24 | * @param bool $autoDetect
25 | * @return $this
26 | */
27 | public function setAutoDetect(bool $autoDetect): self {
28 | $this->autoDetect = $autoDetect;
29 | return $this;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/CircuitBreaker.php:
--------------------------------------------------------------------------------
1 | expression ?? null;
21 | }
22 |
23 | /**
24 | * @param string $expression
25 | * @return $this
26 | */
27 | public function setExpression(string $expression): self {
28 | $this->expression = $expression;
29 | return $this;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Retry.php:
--------------------------------------------------------------------------------
1 | attempts ?? null;
24 | }
25 |
26 | /**
27 | * @param int $attempts
28 | * @return $this
29 | */
30 | public function setAttempts(int $attempts): self {
31 | $this->attempts = $attempts;
32 | return $this;
33 | }
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Compress.php:
--------------------------------------------------------------------------------
1 | excludedContentTypes ?? null;
21 | }
22 |
23 | /**
24 | * @param string $excludedContentType
25 | * @return $this
26 | */
27 | public function addExcludedContentType(string $excludedContentType): self {
28 | $this->excludedContentTypes[] = $excludedContentType;
29 | return $this;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/StripPrefixRegex.php:
--------------------------------------------------------------------------------
1 | regex ?? null;
24 | }
25 |
26 | /**
27 | * @param string $regex
28 | * @return $this
29 | */
30 | public function addRegex(string $regex): self {
31 | $this->regex[] = $regex;
32 | return $this;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/ReplacePathRegex.php:
--------------------------------------------------------------------------------
1 | getRegex() ){
18 | $this->middlewareData['regex'] = $regex;
19 | }
20 |
21 | if ($replacement = $config->getReplacement()) {
22 | $this->middlewareData['replacement'] = $replacement;
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # https://editorconfig.org/
2 |
3 | root = true
4 |
5 | [*]
6 | trim_trailing_whitespace = true
7 | insert_final_newline = true
8 | end_of_line = lf
9 | charset = utf-8
10 | tab_width = 4
11 |
12 | [{*.{awk,bat,c,cpp,d,h,l,re,skl,w32,y},Makefile*}]
13 | indent_size = 4
14 | indent_style = tab
15 |
16 | [*.{dtd,html,inc,php,phpt,rng,wsdl,xml,xsd,xsl}]
17 | indent_size = 4
18 | indent_style = space
19 |
20 | [*.{ac,m4,sh,yml}]
21 | indent_size = 2
22 | indent_style = space
23 |
24 | [*.md]
25 | indent_style = space
26 | max_line_length = 80
27 |
28 | [COMMIT_EDITMSG]
29 | indent_size = 4
30 | indent_style = space
31 | max_line_length = 80
32 |
33 | [*.patch]
34 | trim_trailing_whitespace = false
35 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/ErrorPage.php:
--------------------------------------------------------------------------------
1 | getQuery() )
17 | {
18 | $this->middlewareData['query'] = $query;
19 | }
20 | if( $service = $config->getService() )
21 | {
22 | $this->middlewareData['service'] = $service;
23 | }
24 | if( $status = $config->getStatus() )
25 | {
26 | $this->middlewareData['status'] = $status;
27 | }
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/RedirectRegex.php:
--------------------------------------------------------------------------------
1 | getRegex()) {
17 | $this->middlewareData['regex'] = $regex;
18 | }
19 | if ($replacement = $config->getReplacement()) {
20 | $this->middlewareData['replacement'] = $replacement;
21 | }
22 | if (!is_null($config->getPermanent())) {
23 | $this->middlewareData['permanent'] = $config->getPermanent();
24 | }
25 |
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/RedirectScheme.php:
--------------------------------------------------------------------------------
1 | getScheme()) {
19 | $this->middlewareData['scheme'] = $scheme;
20 | }
21 | if ($port = $config->getPort()) {
22 | $this->middlewareData['port'] = $port;
23 | }
24 | if (!is_null($config->getPermanent())) {
25 | $this->middlewareData['permanent'] = $config->getPermanent();
26 | }
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/RateLimit.php:
--------------------------------------------------------------------------------
1 | getAverage()) {
16 | $this->middlewareData['average'] = $average;
17 | }
18 | if ($period = $config->getPeriod()) {
19 | $this->middlewareData['period'] = $period;
20 | }
21 | if ($burst = $config->getBurst()) {
22 | $this->middlewareData['burst'] = $burst;
23 | }
24 | if ($sourceCriterion = $config->getSourceCriterion()) {
25 | $this->middlewareData['sourceCriterion'] = $sourceCriterion->getData();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Traefik/Tcp/Router.php:
--------------------------------------------------------------------------------
1 | $this->getEntryPoints(),
16 | 'service' => $this->getService()
17 | ];
18 |
19 | if ($rule = $this->getRule()) {
20 | $routerData['rule'] = $rule;
21 | }
22 |
23 | if ($this->tls) {
24 | $routerData['tls'] = [
25 | 'passthrough' => 'true'
26 | ];
27 | }
28 |
29 | if (isset($this->priority)) {
30 | $routerData['priority'] = $this->priority;
31 | }
32 |
33 | if (isset($this->middlewares)) {
34 | $routerData['middlewares'] = $this->middlewares;
35 | }
36 |
37 | return $routerData;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Traefik/Udp/Router.php:
--------------------------------------------------------------------------------
1 | $this->getEntryPoints(),
16 | 'service' => $this->getService()
17 | ];
18 |
19 | if ($rule = $this->getRule()) {
20 | $routerData['rule'] = $rule;
21 | }
22 |
23 | if ($this->tls) {
24 | $routerData['tls'] = [
25 | 'passthrough' => 'true'
26 | ];
27 | }
28 |
29 | if (isset($this->priority)) {
30 | $routerData['priority'] = $this->priority;
31 | }
32 |
33 | if (isset($this->middlewares)) {
34 | $routerData['middlewares'] = $this->middlewares;
35 | }
36 |
37 | return $routerData;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Traefik/Http/Router.php:
--------------------------------------------------------------------------------
1 | $this->getEntryPoints(),
16 | 'service' => $this->getService()
17 | ];
18 |
19 | if ($rule = $this->getRule()) {
20 | $routerData['rule'] = $rule;
21 | }
22 |
23 | if ($this->tls) {
24 | $routerData['tls'] = [
25 | 'certResolver' => 'letsencrypt'
26 | ];
27 | }
28 |
29 | if (isset($this->priority)) {
30 | $routerData['priority'] = $this->priority;
31 | }
32 |
33 | if (isset($this->middlewares)) {
34 | $routerData['middlewares'] = $this->middlewares;
35 | }
36 |
37 | return $routerData;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/IpWhiteList.php:
--------------------------------------------------------------------------------
1 | getIpStrategyDepth()) {
17 | $this->middlewareData['ipStrategy']['depth'] = $ipStrategyDepth;
18 | }
19 | $ipStrategyExcludedIPs = $config->getIpStrategyExcludedIPs();
20 | if (!empty($ipStrategyExcludedIPs)) {
21 | $this->middlewareData['ipStrategy']['excludedIPs'] = $ipStrategyExcludedIPs;
22 | }
23 | $sourceRange = $config->getSourceRange();
24 | if (!empty($sourceRange)) {
25 | $this->middlewareData['sourceRange'] = $sourceRange;
26 | }
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/ForwardAuth.php:
--------------------------------------------------------------------------------
1 | getAuthResponseHeaders()) {
17 | $this->middlewareData['authResponseHeaders'] = $authResponseHeaders;
18 | }
19 | if (!is_null($config->getTrustForwardHeader())) {
20 | $this->middlewareData['trustForwardHeader'] = $config->getTrustForwardHeader();
21 | }
22 | if ($tls = $config->getTls()) {
23 | $this->middlewareData['tls'] = $tls->getData();
24 | }
25 | if ($address = $config->getAddress()) {
26 | $this->middlewareData['address'] = $address;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Traefik/Http/Middleware.php:
--------------------------------------------------------------------------------
1 | name;
19 | }
20 |
21 | public function setName($name) {
22 | $this->name = $name;
23 | return $this;
24 | }
25 |
26 | public function setMiddleware(MiddlewareInterface $middleware) {
27 | $this->middleware = $middleware;
28 | return $this;
29 | }
30 |
31 | public function getData(): array {
32 | $data = $this->middleware->getData();
33 |
34 | if (empty($data)) {
35 | $data = (new \stdClass());
36 | }
37 |
38 | return [
39 | $this->middleware->getName() => $data
40 | ];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Traefik/Tcp/Service.php:
--------------------------------------------------------------------------------
1 | terminationDelay = $delay;
17 | return $this;
18 | }
19 |
20 | public function getTerminationDelay(): int {
21 | return $this->terminationDelay;
22 | }
23 |
24 | public function addServer(string $url): self {
25 | $this->servers[] = (new Server($url));
26 | return $this;
27 | }
28 |
29 | public function getData(): array {
30 | $data = [
31 | $this->getServerKey() => $this->getServers()
32 | ];
33 | if (isset($this->terminationDelay)) {
34 | $data['terminationDelay'] = $this->getTerminationDelay();
35 | }
36 |
37 | return [$this->getType() => $data];
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/DigestAuth.php:
--------------------------------------------------------------------------------
1 | getUsers() ) {
17 | $this->middlewareData['users'] = $users;
18 | }
19 | if($usersFile = $config->getUsersFile() ) {
20 | $this->middlewareData['usersFile'] = $usersFile;
21 | }
22 | if($realm = $config->getRealm() ) {
23 | $this->middlewareData['realm'] = $realm;
24 | }
25 | if(!is_null($config->getRemoveHeader()) ) {
26 | $this->middlewareData['removeHeader'] = $config->getRemoveHeader();
27 | }
28 | if($headerField = $config->getHeaderField() ) {
29 | $this->middlewareData['headerField'] = $headerField;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | stages:
2 | - test
3 | - deploy
4 |
5 | variables:
6 | DOCKER_DRIVER: overlay2
7 |
8 | unit_test:
9 | image: php:8
10 | # before_script:
11 | # - apt-get update && apt-get install -y git
12 | # - curl -fsSL https://getcomposer.org/download/2.0.8/composer.phar -o /usr/local/bin/composer && chmod +x /usr/local/bin/composer
13 | # - composer install
14 | script:
15 | # - ./vendor/bin/phpunit --testdox tests
16 | - curl -fsSL https://phar.phpunit.de/phpunit-9.phar -o /usr/local/bin/phpunit && chmod +x /usr/local/bin/phpunit
17 | - /usr/local/bin/phpunit --bootstrap ./tests/bootstrap.php --testdox tests
18 |
19 | deploy_composer_tag:
20 | image: curlimages/curl:7.72.0
21 | only:
22 | - tags
23 | stage: deploy
24 | script:
25 | - 'curl --header "Job-Token: ${CI_JOB_TOKEN}" --data tag="${CI_COMMIT_TAG}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/composer"'
26 |
27 | deploy_composer_branch:
28 | image: curlimages/curl:7.72.0
29 | only:
30 | - branches
31 | stage: deploy
32 | script:
33 | - 'curl --header "Job-Token: ${CI_JOB_TOKEN}" --data branch="${CI_COMMIT_BRANCH}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/composer"'
34 |
35 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/ReplacePathRegex.php:
--------------------------------------------------------------------------------
1 | regex ?? null;
22 | }
23 |
24 | /**
25 | * @param string $regex
26 | * @return $this
27 | */
28 | public function setRegex(string $regex): self {
29 | $this->regex = $regex;
30 | return $this;
31 | }
32 |
33 | /**
34 | * @return string|null
35 | */
36 | public function getReplacement(): ?string {
37 | return $this->replacement ?? null;
38 | }
39 |
40 | /**
41 | * @param string $replacement
42 | * @return $this
43 | */
44 | public function setReplacement(string $replacement): self {
45 | $this->replacement = $replacement;
46 | return $this;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/BasicAuth.php:
--------------------------------------------------------------------------------
1 | getUsersFile()) {
17 | $this->middlewareData['usersFile'] = $usersFile;
18 | }
19 |
20 | if ($realm = $config->getRealm()) {
21 | $this->middlewareData['realm'] = $realm;
22 | }
23 |
24 | if ($headerField = $config->getHeaderField()) {
25 | $this->middlewareData['headerField'] = $headerField;
26 | }
27 |
28 | if ($users = $config->getUsers()) {
29 | $this->middlewareData['users'] = $users;
30 | }
31 |
32 | if (!is_null($config->getRemoveHeader())) {
33 | $this->middlewareData['removeHeader'] = $config->getRemoveHeader();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/StripPrefix.php:
--------------------------------------------------------------------------------
1 | prefixes ?? null;
25 | }
26 |
27 | /**
28 | * @param string $prefix
29 | * @return $this
30 | */
31 | public function addPrefixes(string $prefix): self {
32 | $this->prefixes[] = $prefix;
33 | return $this;
34 | }
35 |
36 | /**
37 | * @return bool|null
38 | */
39 | public function getForceSlash(): ?bool {
40 | return $this->forceSlash ?? null;
41 | }
42 |
43 | /**
44 | * @param bool $forceSlash
45 | * @return $this
46 | */
47 | public function setForceSlash(bool $forceSlash): self {
48 | $this->forceSlash = $forceSlash;
49 | return $this;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/MiddlewareAbstract.php:
--------------------------------------------------------------------------------
1 | middlewareOptions as $middlewareOption) {
19 | if (isset($config[$middlewareOption])) {
20 | $methodName = 'set' . $middlewareOption;
21 | if (\method_exists($this, \ucfirst($methodName))) {
22 | $this->middlewareData[$middlewareOption] = $this->{$methodName}($config[$middlewareOption]);
23 | } else {
24 | $this->middlewareData[$middlewareOption] = $config[$middlewareOption];
25 | }
26 | }
27 | }
28 | }
29 |
30 | public function getName(): string {
31 | return $this->middlewareName;
32 | }
33 |
34 | public function getData(): array {
35 | return $this->middlewareData;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Buffering.php:
--------------------------------------------------------------------------------
1 | getRetryExpression()) {
17 | $this->middlewareData['retryExpression'] = $retryExpression;
18 | }
19 |
20 | if ($memResponseBodyBytes = $config->getMemResponseBodyBytes()) {
21 | $this->middlewareData['memResponseBodyBytes'] = $memResponseBodyBytes;
22 | }
23 |
24 | if ($maxResponseBodyBytes = $config->getMaxResponseBodyBytes()) {
25 | $this->middlewareData['maxResponseBodyBytes'] = $maxResponseBodyBytes;
26 | }
27 |
28 | if ($memRequestBodyBytes = $config->getMemRequestBodyBytes()) {
29 | $this->middlewareData['memRequestBodyBytes'] = $memRequestBodyBytes;
30 | }
31 |
32 | if ($maxRequestBodyBytes = $config->getMaxRequestBodyBytes()) {
33 | $this->middlewareData['maxRequestBodyBytes'] = $maxRequestBodyBytes;
34 | }
35 |
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/InFlightReq.php:
--------------------------------------------------------------------------------
1 | amount ?? null;
23 | }
24 |
25 | /**
26 | * @param int $amount
27 | * @return $this
28 | */
29 | public function setAmount(int $amount): self {
30 | $this->amount = $amount;
31 | return $this;
32 | }
33 |
34 | /**
35 | * @return \Traefik\Middleware\Config\SourceCriterion|null
36 | */
37 | public function getSourceCriterion(): ?SourceCriterion {
38 | return $this->sourceCriterion ?? null;
39 | }
40 |
41 | /**
42 | * @param \Traefik\Middleware\Config\SourceCriterion $sourceCriterion
43 | * @return $this
44 | */
45 | public function setSourceCriterion(SourceCriterion $sourceCriterion): self {
46 | $this->sourceCriterion = $sourceCriterion;
47 | return $this;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Traefik/Udp/Service.php:
--------------------------------------------------------------------------------
1 | terminationDelay = $delay;
23 | return $this;
24 | }
25 |
26 | /**
27 | *
28 | * @param integer $delay
29 | * @return self
30 | */
31 | public function getTerminationDelay(): int {
32 | return $this->terminationDelay;
33 | }
34 |
35 | /**
36 | * @param string $url
37 | * @return self
38 | */
39 | public function addServer(string $url): self {
40 | $this->servers[] = (new Server($url));
41 | return $this;
42 | }
43 |
44 | /**
45 | * @return array[]
46 | */
47 | public function getData(): array {
48 | $data = [
49 | $this->getServerKey() => $this->getServers()
50 | ];
51 | if (isset($this->terminationDelay)) {
52 | $data['terminationDelay'] = $this->getTerminationDelay();
53 | }
54 |
55 | return [$this->getType() => $data];
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Traefik/Http/Service.php:
--------------------------------------------------------------------------------
1 | passHostHeader = $status;
23 | return $this;
24 | }
25 |
26 | /**
27 | *
28 | * @param boolean $status
29 | * @return void
30 | */
31 | public function getPassHostHeader(): bool {
32 | return $this->passHostHeader;
33 | }
34 |
35 | /**
36 | *
37 | * @param boolean $status
38 | * @return void
39 | */
40 | public function addServer(string $url): self {
41 | $this->servers[] = (new Server($url));
42 | return $this;
43 | }
44 |
45 | /**
46 | *
47 | * @param boolean $status
48 | * @return void
49 | */
50 | public function getData(): array {
51 | return [
52 | $this->getType() => [
53 | 'passHostHeader' => $this->getPassHostHeader(),
54 | $this->getServerKey() => $this->getServers()
55 | ]
56 | ];
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/RateLimit.php:
--------------------------------------------------------------------------------
1 | average ?? null;
20 | }
21 |
22 | public function setAverage(int $average): self {
23 | $this->average = $average;
24 | return $this;
25 | }
26 |
27 | public function getPeriod(): ?string {
28 | return $this->period ?? null;
29 | }
30 |
31 | public function setPeriod(string $period): self {
32 | $this->period = $period;
33 | return $this;
34 | }
35 |
36 | public function getBurst(): ?int {
37 | return $this->burst ?? null;
38 | }
39 |
40 | public function setBurst(int $burst): self {
41 | $this->burst = $burst;
42 | return $this;
43 | }
44 |
45 | public function getSourceCriterion(): ?SourceCriterion {
46 | return $this->sourceCriterion ?? null;
47 | }
48 |
49 | public function setSourceCriterion(SourceCriterion $sourceCriterion): self {
50 | $this->sourceCriterion = $sourceCriterion;
51 | return $this;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/docker-compose/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3.8'
2 | services:
3 | traefik:
4 | image: traefik:2.3
5 |
6 | command:
7 | # https://doc.traefik.io/traefik/v2.3/reference/static-configuration/cli/
8 | - "--log.level=DEBUG"
9 | - "--api.insecure=true"
10 | - "--providers.http.endpoint=http://api/index.php"
11 | - "--providers.http.pollInterval=5s"
12 |
13 | - "--entrypoints.http.address=:80"
14 | - "--entrypoints.https.address=:443"
15 | - "--entrypoints.database.address=:3306"
16 |
17 | - "--accesslog"
18 | - "--global.checkNewVersion=true"
19 | - "--global.sendAnonymousUsage=false"
20 | - "--serversTransport.insecureSkipVerify=true"
21 | - "--api.insecure=true"
22 | - "--api.debug=true"
23 | - "--api.dashboard=true"
24 | # - "--certificatesResolvers.letsencrypt.acme.email=example@email.com"
25 | # - "--certificatesResolvers.letsencrypt.acme.storage=/acme/acme-tls.json"
26 | # - "--certificatesResolvers.letsencrypt.acme.tlsChallenge"
27 |
28 | volumes:
29 | # SSL certificates
30 | - ./acme:/acme
31 | ports:
32 | - 8080:8080
33 | - 80:80
34 | - 3306:3306
35 | depends_on:
36 | - api
37 |
38 | composer:
39 | image: composer:1
40 | volumes:
41 | - ./html:/app
42 | command: ["composer", "install", "--no-dev"]
43 |
44 | api:
45 | image: php:8-apache
46 | volumes:
47 | - ./html:/var/www/html
48 | depends_on:
49 | - composer
50 | ports:
51 | - 8888:80
52 |
--------------------------------------------------------------------------------
/docker-compose/html/index.php:
--------------------------------------------------------------------------------
1 | setHttpService('magento_service', 'http://magento:80');
9 | $config->setHttpRouter('magento_router', 'Host(`magento.test`)', 'magento_service')
10 | ->setEntryPoints(['http', 'https']);
11 |
12 | $config->setTcpService('magento_database_service', 'magento_db:3306');
13 | $config->setTcpRouter('magento_database_router', 'HostSNI(`magento.test`)', 'magento_database_service')
14 | ->setEntryPoints(['database']);
15 | ### Magento
16 |
17 | ### Magento V2
18 | $config->setHttpService('magentov2_service', 'http://magentov2:80');
19 | $config->setHttpRouter('magentov2_router', 'Host(`magento-v2.test`)', 'magentov2_service')
20 | ->setEntryPoints(['http', 'https']);
21 |
22 | $config->setTcpService('magentov2_database_service', 'magentov2_db:3306');
23 | $config->setTcpRouter('magentov2_database_router', 'HostSNI(`magento-v2.test`)', 'magentov2_database_service')
24 | ->setEntryPoints(['database']);
25 | ### Magento V2
26 |
27 | ### Joomla
28 | $config->setHttpService('joomla_service', 'http://joomla:80');
29 | $config->setHttpRouter('joomla_router', 'Host(`joomla.test`)', 'joomla_service')
30 | ->setEntryPoints(['http', 'https']);
31 |
32 | $config->setTcpService('joomla_database_service', 'joomla_db:3306');
33 | $config->setTcpRouter('joomla_database_router', 'HostSNI(`joomla.test`)', 'joomla_database_service')
34 | ->setEntryPoints(['database']);
35 | ### Joomla
36 | echo $config->getJsonConfig();
37 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/ErrorPage.php:
--------------------------------------------------------------------------------
1 | query ?? null;
23 | }
24 |
25 | /**
26 | * @param string $query
27 | * @return $this
28 | */
29 | public function setQuery(string $query): self {
30 | $this->query = $query;
31 | return $this;
32 | }
33 |
34 | /**
35 | * @return string|null
36 | */
37 | public function getService(): ?string {
38 | return $this->service ?? null;
39 | }
40 |
41 | /**
42 | * @param string $service
43 | * @return $this
44 | */
45 | public function setService(string $service): self {
46 | $this->service = $service;
47 | return $this;
48 | }
49 |
50 | /**
51 | * @return array|null
52 | */
53 | public function getStatus(): ?array {
54 | return $this->status ?? null;
55 | }
56 |
57 | /**
58 | * @param string $status
59 | * @return $this
60 | */
61 | public function addStatus(string $status): self {
62 | $this->status[] = $status;
63 | return $this;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/RedirectScheme.php:
--------------------------------------------------------------------------------
1 | scheme ?? null;
23 | }
24 |
25 | /**
26 | * @param string $scheme
27 | * @return $this
28 | */
29 | public function setScheme(string $scheme): self {
30 | $this->scheme = $scheme;
31 | return $this;
32 | }
33 |
34 | /**
35 | * @return string|null
36 | */
37 | public function getPort(): ?string {
38 | return $this->port ?? null;
39 | }
40 |
41 | /**
42 | * @param string $port
43 | * @return $this
44 | */
45 | public function setPort(string $port): self {
46 | $this->port = $port;
47 | return $this;
48 | }
49 |
50 | /**
51 | * @return bool|null
52 | */
53 | public function getPermanent(): ?bool {
54 | return $this->permanent ?? null;
55 | }
56 |
57 | /**
58 | * @param bool $permanent
59 | * @return $this
60 | */
61 | public function setPermanent(bool $permanent): self {
62 | $this->permanent = $permanent;
63 | return $this;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/PassTLSClientCert.php:
--------------------------------------------------------------------------------
1 | getPem() ) ) {
17 | $this->middlewareData['pem'] = $config->getPem();
18 | }
19 | if( !is_null( $config->getInfoNotAfter() ) ) {
20 | $this->middlewareData['info']['notAfter'] = $config->getInfoNotAfter();
21 | }
22 | if( !is_null( $config->getInfoNotBefore() ) ) {
23 | $this->middlewareData['info']['notBefore'] = $config->getInfoNotBefore();
24 | }
25 | if( !is_null( $config->getInfoSans() ) ) {
26 | $this->middlewareData['info']['sans'] = $config->getInfoSans();
27 | }
28 | if( !is_null( $config->getInfoSerialNumber() ) ) {
29 | $this->middlewareData['info']['serialNumber'] = $config->getInfoSans();
30 | }
31 |
32 | if( $infoSubject = $config->getInfoSubject() ) {
33 | $this->middlewareData['info']['subject'] = $infoSubject->getData();
34 | }
35 | if( $infoIssuer = $config->getInfoIssuer() ) {
36 | $this->middlewareData['info']['issuer'] = $infoIssuer->getData();
37 | }
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/RedirectRegex.php:
--------------------------------------------------------------------------------
1 | regex ?? null;
24 | }
25 |
26 | /**
27 | * @param string $regex
28 | * @return $this
29 | */
30 | public function setRegex(string $regex): self {
31 | $this->regex = $regex;
32 | return $this;
33 | }
34 |
35 | /**
36 | * @return string|null
37 | */
38 | public function getReplacement(): ?string {
39 | return $this->replacement ?? null;
40 | }
41 |
42 | /**
43 | * @param string $replacement
44 | * @return $this
45 | */
46 | public function setReplacement(string $replacement): self {
47 | $this->replacement = $replacement;
48 | return $this;
49 | }
50 |
51 | /**
52 | * @return bool|null
53 | */
54 | public function getPermanent(): ?bool {
55 | return $this->permanent ?? null;
56 | }
57 |
58 | /**
59 | * @param bool $permanent
60 | * @return $this
61 | */
62 | public function setPermanent(bool $permanent): self {
63 | $this->permanent = $permanent;
64 | return $this;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/tests/tcp/TcpServiceTest.php:
--------------------------------------------------------------------------------
1 | service) {
18 | $tcpService = new TcpService();
19 | $tcpService->setName(self::SERVICE_NAME);
20 | $tcpService->setType(TcpService::LOADBALANCER);
21 | $tcpService->addServer(self::SERVER_URL);
22 |
23 | $this->service = $tcpService;
24 | }
25 | return $this->service;
26 | }
27 |
28 | public function testTcpServiceName(): void
29 | {
30 | $this->assertEquals(
31 | self::SERVICE_NAME,
32 | $this->getService()->getName()
33 | );
34 | }
35 |
36 | public function testTcpServiceType(): void
37 | {
38 | $data = $this->getService()->getData();
39 | $this->assertArrayHasKey(TcpService::LOADBALANCER, $data);
40 | }
41 |
42 | public function testTcpServiceAddress(): void
43 | {
44 | $data = $this->getService()->getData();
45 |
46 | $this->assertArrayHasKey(TcpService::LOADBALANCER, $data);
47 | $this->assertArrayHasKey('servers', $data[TcpService::LOADBALANCER]);
48 |
49 | $urlList = [];
50 | foreach ($data[TcpService::LOADBALANCER]['servers'] as $server) {
51 | $this->assertInstanceOf(Traefik\Tcp\Server::class, $server);
52 | $urlList[] = $server->address;
53 | }
54 | $this->assertContains(self::SERVER_URL, $urlList);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/tests/udp/UdpServiceTest.php:
--------------------------------------------------------------------------------
1 | service) {
18 | $udpService = new UdpService();
19 | $udpService->setName(self::SERVICE_NAME);
20 | $udpService->setType(UdpService::LOADBALANCER);
21 | $udpService->addServer(self::SERVER_URL);
22 |
23 | $this->service = $udpService;
24 | }
25 | return $this->service;
26 | }
27 |
28 | public function testUdpServiceName(): void
29 | {
30 | $this->assertEquals(
31 | self::SERVICE_NAME,
32 | $this->getService()->getName()
33 | );
34 | }
35 |
36 | public function testUdpServiceType(): void
37 | {
38 | $data = $this->getService()->getData();
39 | $this->assertArrayHasKey(UdpService::LOADBALANCER, $data);
40 | }
41 |
42 | public function testUdpServiceAddress(): void
43 | {
44 | $data = $this->getService()->getData();
45 |
46 | $this->assertArrayHasKey(UdpService::LOADBALANCER, $data);
47 | $this->assertArrayHasKey('servers', $data[UdpService::LOADBALANCER]);
48 |
49 | $urlList = [];
50 | foreach ($data[UdpService::LOADBALANCER]['servers'] as $server) {
51 | $this->assertInstanceOf(Traefik\Udp\Server::class, $server);
52 | $urlList[] = $server->address;
53 | }
54 | $this->assertContains(self::SERVER_URL, $urlList);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/IpWhiteList.php:
--------------------------------------------------------------------------------
1 | ipStrategyDepth ?? null;
23 | }
24 |
25 | /**
26 | * @param int $ipStrategyDepth
27 | * @return $this
28 | */
29 | public function setIpStrategyDepth(int $ipStrategyDepth): self {
30 | $this->ipStrategyDepth = $ipStrategyDepth;
31 | return $this;
32 | }
33 |
34 | /**
35 | * @return array
36 | */
37 | public function getIpStrategyExcludedIPs(): ?array {
38 | return $this->ipStrategyExcludedIPs ?? null;
39 | }
40 |
41 | /**
42 | * @param string $ipStrategyExcludedIP
43 | * @return $this
44 | */
45 | public function addIpStrategyExcludedIP(string $ipStrategyExcludedIP): self {
46 | $this->ipStrategyExcludedIPs[] = $ipStrategyExcludedIP;
47 | return $this;
48 | }
49 |
50 | /**
51 | * @return array
52 | */
53 | public function getSourceRange(): ?array {
54 | return $this->sourceRange ?? null;
55 | }
56 |
57 | /**
58 | * @param string $sourceIp
59 | * @return $this
60 | */
61 | public function addSourceRange(string $sourceIp): self {
62 | $this->sourceRange[] = $sourceIp;
63 | return $this;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/tests/http/HttpServiceTest.php:
--------------------------------------------------------------------------------
1 | service) {
17 | $httpService = new HttpService();
18 | $httpService->setName(self::SERVICE_NAME);
19 | $httpService->setType(HttpService::LOADBALANCER);
20 | $httpService->setPassHostHeader(true);
21 | $httpService->addServer(self::SERVER_URL);
22 |
23 | $this->service = $httpService;
24 | }
25 | return $this->service;
26 | }
27 |
28 | public function testHttpServiceName(): void
29 | {
30 | $this->assertEquals(
31 | self::SERVICE_NAME,
32 | $this->getService()->getName()
33 | );
34 | }
35 |
36 | public function testHttpServiceType(): void
37 | {
38 | $data = $this->getService()->getData();
39 | $this->assertArrayHasKey(HttpService::LOADBALANCER, $data);
40 | }
41 |
42 | public function testHttpServiceUrl(): void
43 | {
44 | $data = $this->getService()->getData();
45 |
46 | $this->assertArrayHasKey(HttpService::LOADBALANCER, $data);
47 | $this->assertArrayHasKey('servers', $data[HttpService::LOADBALANCER]);
48 |
49 | $urlList = [];
50 | foreach ($data[HttpService::LOADBALANCER]['servers'] as $server) {
51 | $urlList[] = $server->url;
52 | }
53 | $this->assertContains(self::SERVER_URL, $urlList, 'url does not match');
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/tests/tcp/TcpRouterTest.php:
--------------------------------------------------------------------------------
1 | service) {
19 | $tcpRouter = new TcpRouter();
20 | $tcpRouter->setEntryPoints([self::ROUTER_ENTRYPOINT]);
21 | $tcpRouter->setName(self::ROUTER_NAME);
22 | $tcpRouter->setRule(self::ROUTER_RULE);
23 | $tcpRouter->setService(self::ROUTER_SERVICE);;
24 |
25 | $this->service = $tcpRouter;
26 | }
27 | return $this->service;
28 | }
29 |
30 | public function testTcpRouterEntrypoints(): void
31 | {
32 | $this->assertContains(
33 | self::ROUTER_ENTRYPOINT,
34 | $this->getService()->getEntryPoints()
35 | );
36 | }
37 |
38 | public function testTcpRouterName(): void
39 | {
40 | $this->assertEquals(
41 | self::ROUTER_NAME,
42 | $this->getService()->getName()
43 | );
44 | }
45 |
46 | public function testTcpRouterRule(): void
47 | {
48 | $data = $this->getService()->getData();
49 |
50 | $this->assertArrayHasKey('rule', $data);
51 | $this->assertEquals(self::ROUTER_RULE, $data['rule']);
52 | }
53 |
54 | public function testTcpRouterService(): void
55 | {
56 | $data = $this->getService()->getData();
57 |
58 | $this->assertArrayHasKey('service', $data);
59 | $this->assertEquals(self::ROUTER_SERVICE, $data['service']);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/tests/udp/UdpRouterTest.php:
--------------------------------------------------------------------------------
1 | service) {
19 | $udpRouter = new UdpRouter();
20 | $udpRouter->setEntryPoints([self::ROUTER_ENTRYPOINT]);
21 | $udpRouter->setName(self::ROUTER_NAME);
22 | $udpRouter->setRule(self::ROUTER_RULE);
23 | $udpRouter->setService(self::ROUTER_SERVICE);;
24 |
25 | $this->service = $udpRouter;
26 | }
27 | return $this->service;
28 | }
29 |
30 | public function testUdpRouterEntrypoints(): void
31 | {
32 | $this->assertContains(
33 | self::ROUTER_ENTRYPOINT,
34 | $this->getService()->getEntryPoints()
35 | );
36 | }
37 |
38 | public function testUdpRouterName(): void
39 | {
40 | $this->assertEquals(
41 | self::ROUTER_NAME,
42 | $this->getService()->getName()
43 | );
44 | }
45 |
46 | public function testUdpRouterRule(): void
47 | {
48 | $data = $this->getService()->getData();
49 |
50 | $this->assertArrayHasKey('rule', $data);
51 | $this->assertEquals(self::ROUTER_RULE, $data['rule']);
52 | }
53 |
54 | public function testUdpRouterService(): void
55 | {
56 | $data = $this->getService()->getData();
57 |
58 | $this->assertArrayHasKey('service', $data);
59 | $this->assertEquals(self::ROUTER_SERVICE, $data['service']);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/Traefik/Service/AbstractObject.php:
--------------------------------------------------------------------------------
1 | name = $name;
22 | return $this;
23 | }
24 |
25 | /**
26 | * @param string $name
27 | * @return self
28 | */
29 | public function getName(): string {
30 | return $this->name;
31 | }
32 |
33 | /**
34 | * @param string $name
35 | * @return self
36 | */
37 | public function setType(string $type): self {
38 | $this->type = $type;
39 | return $this;
40 | }
41 |
42 | /**
43 | * @param string $name
44 | * @return self
45 | */
46 | public function getType(): string {
47 | return $this->type;
48 | }
49 |
50 | /**
51 | * @param string $url
52 | * @return mixed
53 | */
54 | abstract public function addServer(string $url): self;
55 |
56 | /**
57 | * @return array
58 | */
59 | public function getServers(): array {
60 | return $this->servers;
61 | }
62 |
63 | /**
64 | * @return string
65 | */
66 | public function getServerKey(): string {
67 | switch ($this->getType()) {
68 | case self::LOADBALANCER:
69 | return 'servers';
70 | case self::WEIGHTED:
71 | return 'services';
72 | case self::MIRRORING:
73 | return 'mirrors';
74 | }
75 | return 'servers';
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/tests/http/HttpRouterTest.php:
--------------------------------------------------------------------------------
1 | service) {
19 | $httpRouter = new HttpRouter();
20 | $httpRouter->setEntryPoints([self::ROUTER_ENTRYPOINT]);
21 | $httpRouter->setName(self::ROUTER_NAME);
22 | $httpRouter->setRule(self::ROUTER_RULE);
23 | $httpRouter->setService(self::ROUTER_SERVICE);;
24 |
25 | $this->service = $httpRouter;
26 | }
27 | return $this->service;
28 | }
29 |
30 | public function testHttpRouterEntrypoints(): void
31 | {
32 | $this->assertContains(
33 | self::ROUTER_ENTRYPOINT,
34 | $this->getService()->getEntryPoints()
35 | );
36 | }
37 |
38 | public function testHttpRouterName(): void
39 | {
40 | $this->assertEquals(
41 | self::ROUTER_NAME,
42 | $this->getService()->getName()
43 | );
44 | }
45 |
46 | public function testHttpRouterRule(): void
47 | {
48 | $data = $this->getService()->getData();
49 |
50 | $this->assertArrayHasKey('rule', $data);
51 | $this->assertEquals(self::ROUTER_RULE, $data['rule']);
52 | }
53 |
54 | public function testHttpRouterService(): void
55 | {
56 | $data = $this->getService()->getData();
57 |
58 | $this->assertArrayHasKey('service', $data);
59 | $this->assertEquals(self::ROUTER_SERVICE, $data['service']);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/Traefik/RouterObject.php:
--------------------------------------------------------------------------------
1 | priority = $priority;
19 | return $this;
20 | }
21 |
22 | public function getPriority(): int {
23 | return $this->priority;
24 | }
25 |
26 | public function getName(): string {
27 | return $this->name;
28 | }
29 |
30 | public function setName($name): self {
31 | $this->name = $name;
32 | return $this;
33 | }
34 |
35 | public function getRule(): ?string {
36 | return $this->rule ?? null;
37 | }
38 |
39 | public function setRule($rule): self {
40 | if (strlen($rule)) {
41 | $this->rule = $rule;
42 | }
43 | return $this;
44 | }
45 |
46 | public function getService(): string {
47 | return $this->serviceName;
48 | }
49 |
50 | public function setService(string $serviceName): self {
51 | $this->serviceName = $serviceName;
52 | return $this;
53 | }
54 |
55 | public function getTls(): bool {
56 | return $this->tls;
57 | }
58 |
59 | public function setTls(bool $tls): self {
60 | $this->tls = $tls;
61 | return $this;
62 | }
63 |
64 | public function setEntryPoints(array $entryPoints): self {
65 | $this->entryPoints = $entryPoints;
66 | return $this;
67 | }
68 |
69 | public function getEntryPoints(): array {
70 | return $this->entryPoints;
71 | }
72 |
73 | public function setMiddlewares(array $middlewares): self {
74 | $this->middlewares = $middlewares;
75 | return $this;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/ForwardAuth.php:
--------------------------------------------------------------------------------
1 | authResponseHeaders ?? null;
26 | }
27 |
28 | /**
29 | * @param string $authResponseHeader
30 | * @return $this
31 | */
32 | public function addAuthResponseHeaders(string $authResponseHeader): self {
33 | $this->authResponseHeaders[] = $authResponseHeader;
34 | return $this;
35 | }
36 |
37 | /**
38 | * @return bool|null
39 | */
40 | public function getTrustForwardHeader(): ?bool {
41 | return $this->trustForwardHeader ?? null;
42 | }
43 |
44 | /**
45 | * @param bool $trustForwardHeader
46 | * @return $this
47 | */
48 | public function setTrustForwardHeader(bool $trustForwardHeader): self {
49 | $this->trustForwardHeader = $trustForwardHeader;
50 | return $this;
51 | }
52 |
53 | /**
54 | * @return Tls|null
55 | */
56 | public function getTls(): ?Tls {
57 | return $this->tls ?? null;
58 | }
59 |
60 | /**
61 | * @param Tls $tls
62 | * @return $this
63 | */
64 | public function setTls(Tls $tls): self {
65 | $this->tls = $tls;
66 | return $this;
67 | }
68 |
69 | /**
70 | * @return string|null
71 | */
72 | public function getAddress(): ?string {
73 | return $this->address ?? null;
74 | }
75 |
76 | /**
77 | * @param string $address
78 | * @return $this
79 | */
80 | public function setAddress(string $address): self {
81 | $this->address = $address;
82 | return $this;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/docker-compose/html/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "5149d899bdd8d5cb601f82a289f94dfe",
8 | "packages": [
9 | {
10 | "name": "stormbyte/traefik-http-config",
11 | "version": "v0.2.2",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/stormbyte/traefik-http-provider.git",
15 | "reference": "ea90cb93d0493e5820af78cd8e4fe9f57b53d769"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/stormbyte/traefik-http-provider/zipball/ea90cb93d0493e5820af78cd8e4fe9f57b53d769",
20 | "reference": "ea90cb93d0493e5820af78cd8e4fe9f57b53d769",
21 | "shasum": ""
22 | },
23 | "require-dev": {
24 | "phpunit/phpunit": "^9"
25 | },
26 | "type": "library",
27 | "autoload": {
28 | "psr-4": {
29 | "Traefik\\": "src/Traefik"
30 | }
31 | },
32 | "notification-url": "https://packagist.org/downloads/",
33 | "license": [
34 | "MIT"
35 | ],
36 | "authors": [
37 | {
38 | "name": "N.A. Walhof",
39 | "homepage": "http://stormbyte.nl"
40 | }
41 | ],
42 | "description": "A library to generate a Http Provider for Traefik",
43 | "homepage": "http://stormbyte.nl",
44 | "keywords": [
45 | "config",
46 | "http",
47 | "php",
48 | "traefik"
49 | ],
50 | "time": "2021-01-20T20:11:06+00:00"
51 | }
52 | ],
53 | "packages-dev": [],
54 | "aliases": [],
55 | "minimum-stability": "stable",
56 | "stability-flags": [],
57 | "prefer-stable": false,
58 | "prefer-lowest": false,
59 | "platform": [],
60 | "platform-dev": [],
61 | "plugin-api-version": "1.1.0"
62 | }
63 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Buffering.php:
--------------------------------------------------------------------------------
1 | retryExpression ?? null;
21 | }
22 |
23 | /**
24 | * @param string $retryExpression
25 | * @return $this
26 | */
27 | public function setRetryExpression(string $retryExpression): self {
28 | $this->retryExpression = $retryExpression;
29 | return $this;
30 | }
31 |
32 | /**
33 | * @return int|null
34 | */
35 | public function getMemResponseBodyBytes(): ?int {
36 | return $this->memResponseBodyBytes ?? null;
37 | }
38 |
39 | /**
40 | * @param int $memResponseBodyBytes
41 | * @return $this
42 | */
43 | public function setMemResponseBodyBytes(int $memResponseBodyBytes): self {
44 | $this->memResponseBodyBytes = $memResponseBodyBytes;
45 | return $this;
46 | }
47 |
48 | /**
49 | * @return int|null
50 | */
51 | public function getMaxResponseBodyBytes(): ?int {
52 | return $this->maxResponseBodyBytes ?? null;
53 | }
54 |
55 | /**
56 | * @param int $maxResponseBodyBytes
57 | * @return $this
58 | */
59 | public function setMaxResponseBodyBytes(int $maxResponseBodyBytes): self {
60 | $this->maxResponseBodyBytes = $maxResponseBodyBytes;
61 | return $this;
62 | }
63 |
64 | /**
65 | * @return int|null
66 | */
67 | public function getMemRequestBodyBytes(): ?int {
68 | return $this->memRequestBodyBytes ?? null;
69 | }
70 |
71 | /**
72 | * @param int $memRequestBodyBytes
73 | * @return $this
74 | */
75 | public function setMemRequestBodyBytes(int $memRequestBodyBytes): self {
76 | $this->memRequestBodyBytes = $memRequestBodyBytes;
77 | return $this;
78 | }
79 |
80 | /**
81 | * @return int|null
82 | */
83 | public function getMaxRequestBodyBytes(): ?int {
84 | return $this->maxRequestBodyBytes ?? null;
85 | }
86 |
87 | /**
88 | * @param int $maxRequestBodyBytes
89 | * @return $this
90 | */
91 | public function setMaxRequestBodyBytes(int $maxRequestBodyBytes): self {
92 | $this->maxRequestBodyBytes = $maxRequestBodyBytes;
93 | return $this;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/SourceCriterion.php:
--------------------------------------------------------------------------------
1 | requestHeaderName ?? null;
17 | }
18 |
19 | /**
20 | * @param string $requestHeaderName
21 | * @return $this
22 | */
23 | public function setRequestHeaderName(string $requestHeaderName): self {
24 | $this->requestHeaderName = $requestHeaderName;
25 | return $this;
26 | }
27 |
28 | /**
29 | * @return bool|null
30 | */
31 | public function getRequestHost(): ?bool {
32 | return $this->requestHost ?? null;
33 | }
34 |
35 | /**
36 | * @param bool $requestHost
37 | * @return $this
38 | */
39 | public function setRequestHost(bool $requestHost): self {
40 | $this->requestHost = $requestHost;
41 | return $this;
42 | }
43 |
44 | /**
45 | * @return int|null
46 | */
47 | public function getIpStrategyDepth(): ?int {
48 | return $this->ipStrategyDepth ?? null;
49 | }
50 |
51 | /**
52 | * @param int $ipStrategyDepth
53 | * @return $this
54 | */
55 | public function setIpStrategyDepth(int $ipStrategyDepth): self {
56 | $this->ipStrategyDepth = $ipStrategyDepth;
57 | return $this;
58 | }
59 |
60 | /**
61 | * @return array
62 | */
63 | public function getIpStrategyExcludedIPs(): array {
64 | return $this->ipStrategyExcludedIPs;
65 | }
66 |
67 | /**
68 | * @param string $ipStrategyExcludedIP
69 | * @return $this
70 | */
71 | public function addIpStrategyExcludedIP(string $ipStrategyExcludedIP): self {
72 | $this->ipStrategyExcludedIPs[] = $ipStrategyExcludedIP;
73 | return $this;
74 | }
75 |
76 | /**
77 | * @return array|null
78 | */
79 | public function getData(): ?array {
80 | $dataArray = [];
81 |
82 | if ($requestHeaderName = $this->getRequestHeaderName()) {
83 | $dataArray['requestHeaderName'] = $requestHeaderName;
84 | }
85 | if ($requestHost = $this->getRequestHost()) {
86 | $dataArray['requestHost'] = $requestHost;
87 | }
88 | if ($ipStrategyDepth = $this->getIpStrategyDepth()) {
89 | $dataArray['ipStrategy']['depth'] = $ipStrategyDepth;
90 | }
91 | $ipStrategyExcludedIPs = $this->getIpStrategyExcludedIPs();
92 | if (!empty($ipStrategyExcludedIPs)) {
93 | $dataArray['ipStrategy']['excludedIPs'] = $ipStrategyExcludedIPs;
94 | }
95 |
96 | return (!empty($dataArray)) ? $dataArray : null;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/BasicAuth.php:
--------------------------------------------------------------------------------
1 | usersFile ?? null;
26 | }
27 |
28 | /**
29 | * @param string $usersFile
30 | * @return $this
31 | */
32 | public function setUsersFile(string $usersFile): self {
33 | $this->usersFile = $usersFile;
34 | return $this;
35 | }
36 |
37 | /**
38 | * @return string|null
39 | */
40 | public function getRealm(): ?string {
41 | return $this->realm ?? null;
42 | }
43 |
44 | /**
45 | * @param string $realm
46 | * @return $this
47 | */
48 | public function setRealm(string $realm): self {
49 | $this->realm = $realm;
50 | return $this;
51 | }
52 |
53 | /**
54 | * @return bool|null
55 | */
56 | public function getRemoveHeader(): ?bool {
57 | return $this->removeHeader ?? null;
58 | }
59 |
60 | /**
61 | * @param bool $removeHeader
62 | * @return $this
63 | */
64 | public function setRemoveHeader(bool $removeHeader): self {
65 | $this->removeHeader = $removeHeader;
66 | return $this;
67 | }
68 |
69 | /**
70 | * @return string|null
71 | */
72 | public function getHeaderField(): ?string {
73 | return $this->headerField ?? null;
74 | }
75 |
76 | /**
77 | * @param string $headerField
78 | * @return $this
79 | */
80 | public function setHeaderField(string $headerField): self {
81 | $this->headerField = $headerField;
82 | return $this;
83 | }
84 |
85 | /**
86 | * @return array|null
87 | */
88 | public function getUsers(): ?array {
89 | return $this->users ?? null;
90 | }
91 |
92 | /**
93 | * @param string $user
94 | * @param string $password
95 | * @return $this
96 | */
97 | public function addUserWithPassword(string $user, string $password): self {
98 | $userStr = $user . ':' . self::bcrypt($password);
99 | return $this->addUser($userStr);
100 | }
101 |
102 | /**
103 | * @param string $userStr
104 | * @return $this
105 | */
106 | public function addUser(string $userStr): self {
107 | $this->users[] = $userStr;
108 | return $this;
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Tls.php:
--------------------------------------------------------------------------------
1 | insecureSkipVerify;
21 | }
22 |
23 | /**
24 | * @param bool $insecureSkipVerify
25 | * @return $this
26 | */
27 | public function setInsecureSkipVerify(bool $insecureSkipVerify): self {
28 | $this->insecureSkipVerify = $insecureSkipVerify;
29 | return $this;
30 | }
31 |
32 | /**
33 | * @return string
34 | */
35 | public function getKey(): string {
36 | return $this->key;
37 | }
38 |
39 | /**
40 | * @param string $key
41 | * @return $this
42 | */
43 | public function setKey(string $key): self {
44 | $this->key = $key;
45 | return $this;
46 | }
47 |
48 | /**
49 | * @return string
50 | */
51 | public function getCert(): string {
52 | return $this->cert;
53 | }
54 |
55 | /**
56 | * @param string $cert
57 | * @return $this
58 | */
59 | public function setCert(string $cert): self {
60 | $this->cert = $cert;
61 | return $this;
62 | }
63 |
64 | /**
65 | * @return bool
66 | */
67 | public function getCaOptional(): bool {
68 | return $this->caOptional;
69 | }
70 |
71 | /**
72 | * @param bool $caOptional
73 | * @return $this
74 | */
75 | public function setCaOptional(bool $caOptional): self {
76 | $this->caOptional = $caOptional;
77 | return $this;
78 | }
79 |
80 | /**
81 | * @return string
82 | */
83 | public function getCa(): string {
84 | return $this->ca;
85 | }
86 |
87 | /**
88 | * @param string $ca
89 | * @return $this
90 | */
91 | public function setCa(string $ca): self {
92 | $this->ca = $ca;
93 | return $this;
94 | }
95 |
96 | /**
97 | * @return array|null
98 | */
99 | public function getData(): ?array {
100 | $dataArray = [];
101 |
102 | if ($ca = $this->getCa()) {
103 | $dataArray['ca'] = $ca;
104 | }
105 | if (!is_null($this->getCaOptional())) {
106 | $dataArray['caOptional'] = $this->getCaOptional();
107 | }
108 | if ($cert = $this->getCert()) {
109 | $dataArray['cert'] = $cert;
110 | }
111 | if ($key = $this->getKey()) {
112 | $dataArray['key'] = $key;
113 | }
114 | if (!is_null($this->getInsecureSkipVerify())) {
115 | $dataArray['insecureSkipVerify'] = $this->getInsecureSkipVerify();
116 | }
117 |
118 | return (!empty($dataArray)) ? $dataArray : null;
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/DigestAuth.php:
--------------------------------------------------------------------------------
1 | users ?? null;
29 | }
30 |
31 | /**
32 | * @param string $user
33 | * @return $this
34 | */
35 | public function addUser(string $user): self {
36 | $this->users = $this->users ?? [];
37 | $this->users[] = $user;
38 | return $this;
39 | }
40 |
41 | /**
42 | * @param string $username
43 | * @param string $password
44 | * @param string|null $realm
45 | * @return $this
46 | */
47 | public function addUserWithPassword(string $username, string $password, ?string $realm = null): self {
48 |
49 | $user = $username . ':' . $password . ':' . self::htdigest($username, ($realm ?? $this->getRealm()), $password);
50 | return $this->addUser($user);
51 | }
52 |
53 | /**
54 | * @return string|null
55 | */
56 | public function getUsersFile(): ?string {
57 | return $this->usersFile ?? null;
58 | }
59 |
60 | /**
61 | * @param string $usersFile
62 | * @return $this
63 | */
64 | public function setUsersFile(string $usersFile): self {
65 | $this->usersFile = $usersFile;
66 | return $this;
67 | }
68 |
69 | /**
70 | * @return string|null
71 | */
72 | public function getRealm(): ?string {
73 | return $this->realm ?? null;
74 | }
75 |
76 | /**
77 | * @param string $realm
78 | * @return $this
79 | */
80 | public function setRealm(string $realm): self {
81 | $this->realm = $realm;
82 | return $this;
83 | }
84 |
85 | /**
86 | * @return bool|null
87 | */
88 | public function getRemoveHeader(): ?bool {
89 | return $this->removeHeader ?? null;
90 | }
91 |
92 | /**
93 | * @param bool $removeHeader
94 | * @return $this
95 | */
96 | public function setRemoveHeader(bool $removeHeader): self {
97 | $this->removeHeader = $removeHeader;
98 | return $this;
99 | }
100 |
101 | /**
102 | * @return string|null
103 | */
104 | public function getHeaderField(): ?string {
105 | return $this->headerField ?? null;
106 | }
107 |
108 | /**
109 | * @param string $headerField
110 | * @return $this
111 | */
112 | public function setHeaderField(string $headerField): self {
113 | $this->headerField = $headerField;
114 | return $this;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/PassTLSClientCert.php:
--------------------------------------------------------------------------------
1 | pem ?? null;
27 | }
28 |
29 | /**
30 | * @param bool $pem
31 | * @return $this
32 | */
33 | public function setPem(bool $pem): self {
34 | $this->pem = $pem;
35 | return $this;
36 | }
37 |
38 | /**
39 | * @return bool
40 | */
41 | public function getInfoNotAfter(): ?bool {
42 | return $this->infoNotAfter ?? null;
43 | }
44 |
45 | /**
46 | * @param bool $infoNotAfter
47 | * @return $this
48 | */
49 | public function setInfoNotAfter(bool $infoNotAfter): self {
50 | $this->infoNotAfter = $infoNotAfter;
51 | return $this;
52 | }
53 |
54 | /**
55 | * @return bool
56 | */
57 | public function getInfoNotBefore(): ?bool {
58 | return $this->infoNotBefore ?? null;
59 | }
60 |
61 | /**
62 | * @param bool $infoNotBefore
63 | * @return $this
64 | */
65 | public function setInfoNotBefore(bool $infoNotBefore): self {
66 | $this->infoNotBefore = $infoNotBefore;
67 | return $this;
68 | }
69 |
70 | /**
71 | * @return bool
72 | */
73 | public function getInfoSans(): ?bool {
74 | return $this->infoSans ?? null;
75 | }
76 |
77 | /**
78 | * @param bool $infoSans
79 | * @return $this
80 | */
81 | public function setInfoSans(bool $infoSans): self {
82 | $this->infoSans = $infoSans;
83 | return $this;
84 | }
85 |
86 | /**
87 | * @return Certificate|null
88 | */
89 | public function getInfoSubject(): ?Certificate {
90 | return $this->infoSubject ?? null;
91 | }
92 |
93 | /**
94 | * @param Certificate $infoSubject
95 | * @return $this
96 | */
97 | public function setInfoSubject(Certificate $infoSubject): self {
98 | $this->infoSubject = $infoSubject;
99 | return $this;
100 | }
101 |
102 | /**
103 | * @return Certificate|null
104 | */
105 | public function getInfoIssuer(): ?Certificate {
106 | return $this->infoIssuer ?? null;
107 | }
108 |
109 | /**
110 | * @param Certificate $infoIssuer
111 | * @return $this
112 | */
113 | public function setInfoIssuer(Certificate $infoIssuer): self {
114 | $this->infoIssuer = $infoIssuer;
115 | return $this;
116 | }
117 |
118 | /**
119 | * @return bool
120 | */
121 | public function getInfoSerialNumber(): ?bool {
122 | return $this->serialNumber ?? null;
123 | }
124 |
125 | /**
126 | * @param bool $serialNumber
127 | * @return $this
128 | */
129 | public function setInfoSerialNumber(bool $serialNumber): self {
130 | $this->serialNumber = $serialNumber;
131 | return $this;
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | # Http Providers for Traefik
2 |
3 | This package is meant to provide a easy to use [HTTP provider for Traefik](https://doc.traefik.io/traefik/providers/http/).
4 |
5 | The http provider can be set up to update in increments.
6 |
7 | In the `docker-compose` folder there is an example setup of a self contained setup with a interval of 5sec updates.
8 | As long as the config is valid json it should update every 5sec.
9 |
10 | With this package the config will output a valid json for traefik to read.
11 |
12 | ## Http
13 |
14 | ### Service
15 |
16 | https://doc.traefik.io/traefik/routing/services/
17 |
18 | Add a Http Service to the config
19 | `$config->setHttpService( , );`
20 |
21 | The return is the HttpService class,
22 | `\Traefik\Http\Service`
23 |
24 | With `addServer( )` it's possible to add more backend url's
25 |
26 |
27 | ### Router
28 |
29 | https://doc.traefik.io/traefik/routing/routers/
30 |
31 | Add a Http Router to the config
32 | `$config->setHttpRouter( , , )`
33 |
34 | Add the entryPoints with an array
35 | `->setEntryPoints( [ ] )`
36 |
37 | Add middlewares with an array
38 | `->setMiddlewares( [ ] )`
39 |
40 | Add tls to enable SSL
41 | `->setTls(true)`
42 |
43 |
44 | ### Middleware
45 |
46 | https://doc.traefik.io/traefik/middlewares/overview/
47 |
48 | Add a Http Middleware the the config
49 | `$config->addMiddleWare( , )`
50 |
51 | Possible classes
52 |
53 | - `\Traefik\Middleware\Config\AddPrefix`
54 | - `\Traefik\Middleware\Config\BasicAuth`
55 | - `\Traefik\Middleware\Config\Buffering`
56 | - `\Traefik\Middleware\Config\Chain`
57 | - `\Traefik\Middleware\Config\CircuitBreaker`
58 | - `\Traefik\Middleware\Config\Compress`
59 | - `\Traefik\Middleware\Config\DigestAuth`
60 | - `\Traefik\Middleware\Config\ErrorPage`
61 | - `\Traefik\Middleware\Config\ForwardAuth`
62 | - `\Traefik\Middleware\Config\Headers`
63 | - `\Traefik\Middleware\Config\InFlightReq`
64 | - `\Traefik\Middleware\Config\IpWhiteList`
65 | - `\Traefik\Middleware\Config\PassTLSClientCert`
66 | - `\Traefik\Middleware\Config\RateLimit`
67 | - `\Traefik\Middleware\Config\RedirectRegex`
68 | - `\Traefik\Middleware\Config\RedirectScheme`
69 | - `\Traefik\Middleware\Config\ReplacePath`
70 | - `\Traefik\Middleware\Config\ReplacePathRegex`
71 | - `\Traefik\Middleware\Config\Retry`
72 | - `\Traefik\Middleware\Config\StripPrefix`
73 | - `\Traefik\Middleware\Config\StripPrefixRegex`
74 |
75 | ## Tcp
76 |
77 | ### Service
78 |
79 | https://doc.traefik.io/traefik/routing/services/#configuring-tcp-services
80 |
81 | `$config->setTcpService( , )`
82 |
83 | ### Router
84 |
85 | https://doc.traefik.io/traefik/routing/routers/#configuring-tcp-routers
86 |
87 | `$config->setTcpRouter( , , )`
88 | `->setEntryPoints( [ ] )`
89 | `->setTls(true)`
90 |
91 | ## Udp
92 |
93 | ### Service
94 |
95 | https://doc.traefik.io/traefik/routing/services/#configuring-udp-services
96 |
97 | `$config->setUpdService( , )`
98 |
99 | ### Router
100 |
101 | https://doc.traefik.io/traefik/routing/routers/#configuring-udp-routers
102 |
103 | `$config->setUdpRouter( , , )`
104 | `->setEntryPoints( [ ] )`
105 | `->setTls(true)`
106 |
107 | ## Return config
108 |
109 | `echo $config->getJsonConfig()`
110 |
111 |
112 |
113 | ## TODO
114 |
115 | Support for:
116 | - Root TLS settings
117 | https://doc.traefik.io/traefik/https/tls/
118 | - Full http router TLS settings
119 | https://doc.traefik.io/traefik/routing/routers/#tls
120 | - Full tcp router TLS settings
121 | https://doc.traefik.io/traefik/routing/routers/#tls
122 | - Weighted service
123 | https://doc.traefik.io/traefik/routing/services/#weighted-round-robin-service
124 | - Mirroring service
125 | https://doc.traefik.io/traefik/routing/services/#mirroring-service
126 | - Service health check
127 | https://doc.traefik.io/traefik/routing/services/#health-check
128 | - Service sticky sessions
129 | https://doc.traefik.io/traefik/routing/services/#sticky-sessions
130 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Certificate.php:
--------------------------------------------------------------------------------
1 | country ?? null;
20 | }
21 |
22 | /**
23 | * @param bool $country
24 | * @return $this
25 | */
26 | public function setCountry(bool $country): self {
27 | $this->country = $country;
28 | return $this;
29 | }
30 |
31 | /**
32 | * @return bool
33 | */
34 | public function getProvince(): ?bool {
35 | return $this->province ?? null;
36 | }
37 |
38 | /**
39 | * @param bool $province
40 | * @return $this
41 | */
42 | public function setProvince(bool $province): self {
43 | $this->province = $province;
44 | return $this;
45 | }
46 |
47 | /**
48 | * @return bool
49 | */
50 | public function getLocality(): ?bool {
51 | return $this->locality ?? null;
52 | }
53 |
54 | /**
55 | * @param bool $locality
56 | * @return $this
57 | */
58 | public function setLocality(bool $locality): self {
59 | $this->locality = $locality;
60 | return $this;
61 | }
62 |
63 | /**
64 | * @return bool
65 | */
66 | public function getOrganization(): ?bool {
67 | return $this->organization ?? null;
68 | }
69 |
70 | /**
71 | * @param bool $organization
72 | * @return $this
73 | */
74 | public function setOrganization(bool $organization): self {
75 | $this->organization = $organization;
76 | return $this;
77 | }
78 |
79 | /**
80 | * @return bool
81 | */
82 | public function getCommonName(): ?bool {
83 | return $this->commonName ?? null;
84 | }
85 |
86 | /**
87 | * @param bool $commonName
88 | * @return $this
89 | */
90 | public function setCommonName(bool $commonName): self {
91 | $this->commonName = $commonName;
92 | return $this;
93 | }
94 |
95 | /**
96 | * @return bool
97 | */
98 | public function getSerialNumber(): ?bool {
99 | return $this->serialNumber ?? null;
100 | }
101 |
102 | /**
103 | * @param bool $serialNumber
104 | * @return $this
105 | */
106 | public function setSerialNumber(bool $serialNumber): self {
107 | $this->serialNumber = $serialNumber;
108 | return $this;
109 | }
110 |
111 | /**
112 | * @return bool
113 | */
114 | public function getDomainComponent(): ?bool {
115 | return $this->domainComponent ?? null;
116 | }
117 |
118 | /**
119 | * @param bool $domainComponent
120 | * @return $this
121 | */
122 | public function setDomainComponent(bool $domainComponent): self {
123 | $this->domainComponent = $domainComponent;
124 | return $this;
125 | }
126 |
127 | /**
128 | * @return array|null
129 | */
130 | public function getData(): ?array {
131 | $dataArray = [];
132 |
133 | if (!is_null($this->getCountry())) {
134 | $dataArray['country'] = $this->getCountry();
135 | }
136 | if (!is_null($this->getProvince())) {
137 | $dataArray['province'] = $this->getProvince();
138 | }
139 | if (!is_null($this->getLocality())) {
140 | $dataArray['locality'] = $this->getLocality();
141 | }
142 | if (!is_null($this->getOrganization())) {
143 | $dataArray['organization'] = $this->getOrganization();
144 | }
145 | if (!is_null($this->getCommonName())) {
146 | $dataArray['commonName'] = $this->getCommonName();
147 | }
148 | if (!is_null($this->getSerialNumber())) {
149 | $dataArray['serialNumber'] = $this->getSerialNumber();
150 | }
151 | if (!is_null($this->getDomainComponent())) {
152 | $dataArray['domainComponent'] = $this->getDomainComponent();
153 | }
154 |
155 | return (!empty($dataArray)) ? $dataArray : null;
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Headers.php:
--------------------------------------------------------------------------------
1 | getStsIncludeSubdomains() ) ){
19 | $this->middlewareData['stsIncludeSubdomains'] = $config->getStsIncludeSubdomains();
20 | }
21 | if( !is_null( $config->getAddVaryHeader() ) ){
22 | $this->middlewareData['addVaryHeader'] = $config->getAddVaryHeader();
23 | }
24 | if( !is_null( $config->getSslTemporaryRedirect() ) ){
25 | $this->middlewareData['sslTemporaryRedirect'] = $config->getSslTemporaryRedirect();
26 | }
27 | if( !is_null( $config->getContentTypeNosniff() ) ){
28 | $this->middlewareData['contentTypeNosniff'] = $config->getContentTypeNosniff();
29 | }
30 | if( !is_null( $config->getSslRedirect() ) ){
31 | $this->middlewareData['sslRedirect'] = $config->getSslRedirect();
32 | }
33 | if( !is_null( $config->getAccessControlAllowCredentials() ) ){
34 | $this->middlewareData['accessControlAllowCredentials'] = $config->getAccessControlAllowCredentials();
35 | }
36 | if( !is_null( $config->getBrowserXssFilter() ) ){
37 | $this->middlewareData['browserXssFilter'] = $config->getBrowserXssFilter();
38 | }
39 | if( !is_null( $config->getSslForceHost() ) ){
40 | $this->middlewareData['sslForceHost'] = $config->getSslForceHost();
41 | }
42 | if( !is_null( $config->getForceSTSHeader() ) ){
43 | $this->middlewareData['forceSTSHeader'] = $config->getForceSTSHeader();
44 | }
45 | if( !is_null( $config->getFrameDeny() ) ){
46 | $this->middlewareData['frameDeny'] = $config->getFrameDeny();
47 | }
48 | if( !is_null( $config->getDevelopment() ) ){
49 | $this->middlewareData['isDevelopment'] = $config->getDevelopment();
50 | }
51 | if( !is_null( $config->getStsPreload() ) ){
52 | $this->middlewareData['stsPreload'] = $config->getStsPreload();
53 | }
54 |
55 | if( $accessControlAllowOrigin = $config->getAccessControlAllowOrigin() ){
56 | $this->middlewareData['accessControlAllowOrigin'] = $accessControlAllowOrigin;
57 | }
58 | if( $stsSeconds = $config->getStsSeconds() ){
59 | $this->middlewareData['stsSeconds'] = $stsSeconds;
60 | }
61 | if( $sslHost = $config->getSslHost() ){
62 | $this->middlewareData['sslHost'] = $sslHost;
63 | }
64 | if( $contentSecurityPolicy = $config->getContentSecurityPolicy() ){
65 | $this->middlewareData['contentSecurityPolicy'] = $contentSecurityPolicy;
66 | }
67 | if( $referrerPolicy = $config->getReferrerPolicy() ){
68 | $this->middlewareData['referrerPolicy'] = $referrerPolicy;
69 | }
70 | if( $publicKey = $config->getPublicKey() ){
71 | $this->middlewareData['publicKey'] = $publicKey;
72 | }
73 | if( $customBrowserXSSValue = $config->getCustomBrowserXSSValue() ){
74 | $this->middlewareData['customBrowserXSSValue'] = $customBrowserXSSValue;
75 | }
76 | if( $accessControlMaxAge = $config->getAccessControlMaxAge() ){
77 | $this->middlewareData['accessControlMaxAge'] = $accessControlMaxAge;
78 | }
79 | if( $customFrameOptionsValue = $config->getCustomFrameOptionsValue() ){
80 | $this->middlewareData['customFrameOptionsValue'] = $customFrameOptionsValue;
81 | }
82 | if( $featurePolicy = $config->getFeaturePolicy() ){
83 | $this->middlewareData['featurePolicy'] = $featurePolicy;
84 | }
85 | if( $accessControlAllowOriginList = $config->getAccessControlAllowOriginList() ){
86 | $this->middlewareData['accessControlAllowOriginList'] = $accessControlAllowOriginList;
87 | }
88 | if( $accessControlAllowMethods = $config->getAccessControlAllowMethods() ){
89 | $this->middlewareData['accessControlAllowMethods'] = $accessControlAllowMethods;
90 | }
91 | if( $hostsProxyHeaders = $config->getHostsProxyHeaders() ){
92 | $this->middlewareData['hostsProxyHeaders'] = $hostsProxyHeaders;
93 | }
94 | if( $accessControlAllowHeaders = $config->getAccessControlAllowHeaders() ){
95 | $this->middlewareData['accessControlAllowHeaders'] = $accessControlAllowHeaders;
96 | }
97 | if( $allowedHosts = $config->getAllowedHosts() ){
98 | $this->middlewareData['allowedHosts'] = $allowedHosts;
99 | }
100 | if( $accessControlExposeHeaders = $config->getAccessControlExposeHeaders() ){
101 | $this->middlewareData['accessControlExposeHeaders'] = $accessControlExposeHeaders;
102 | }
103 | if( $customRequestHeaders = $config->getCustomRequestHeaders() ){
104 | $this->middlewareData['customRequestHeaders'] = $customRequestHeaders;
105 | }
106 | if( $customResponseHeaders = $config->getCustomResponseHeaders() ){
107 | $this->middlewareData['customResponseHeaders'] = $customResponseHeaders;
108 | }
109 | if( $sslProxyHeaders = $config->getSslProxyHeaders() ){
110 | $this->middlewareData['sslProxyHeaders'] = $sslProxyHeaders;
111 | }
112 |
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/src/Traefik/Config.php:
--------------------------------------------------------------------------------
1 | config['HS'][$name])) {
30 | $this->config['HS'][$name] = (new HttpService())
31 | ->setName($name)
32 | ->setType(HttpService::LOADBALANCER)
33 | ->setPassHostHeader(true)
34 | ->addServer($url);
35 | }
36 | return $this->config['HS'][$name];
37 | }
38 |
39 | /**
40 | * @param string $name
41 | * @param string $rule
42 | * @param string $serviceName
43 | * @return HttpRouter
44 | */
45 | public function setHttpRouter(string $name, string $rule, string $serviceName): HttpRouter {
46 | if (!isset($this->config['HR'][$name])) {
47 | $this->config['HR'][$name] = (new HttpRouter())
48 | ->setName($name)
49 | ->setRule($rule)
50 | ->setService($serviceName);
51 | }
52 | return $this->config['HR'][$name];
53 | }
54 |
55 | /**
56 | * @param string $name
57 | * @param MiddlewareConfigInterface $middlewareConfig
58 | * @return HttpMiddleware
59 | */
60 | public function addMiddleWare(string $name, MiddlewareConfigInterface $middlewareConfig): HttpMiddleware
61 | {
62 | if (isset($this->config['MW'][$name])) {
63 | throw new DuplicateMiddlewareException($name);
64 | }
65 | $middlewareClass = $middlewareConfig->getMiddlewareClassName();
66 | $middleware = (new $middlewareClass( $middlewareConfig ));
67 | return $this->setMiddleWare($name, $middleware);
68 | }
69 |
70 | /**
71 | * @param string $name
72 | * @param MiddlewareInterface $middleware
73 | * @return HttpMiddleware
74 | */
75 | public function setMiddleWare(string $name, MiddlewareInterface $middleware): HttpMiddleware {
76 | if (!isset($this->config['MW'][$name])) {
77 | $this->config['MW'][$name] = (new HttpMiddleware())
78 | ->setName($name)
79 | ->setMiddleware($middleware);
80 | }
81 | return $this->config['MW'][$name];
82 | }
83 |
84 | /**
85 | * @param string $name
86 | * @param string $url
87 | * @return TcpService
88 | */
89 | public function setTcpService(string $name, string $url): TcpService {
90 | if (!isset($this->config['TS'][$name])) {
91 | $this->config['TS'][$name] = (new TcpService())
92 | ->setName($name)
93 | ->setType(TcpService::LOADBALANCER)
94 | ->addServer($url);
95 | }
96 | return $this->config['TS'][$name];
97 | }
98 |
99 | /**
100 | * @param string $name
101 | * @param string $rule
102 | * @param string $serviceName
103 | * @return TcpRouter
104 | */
105 | public function setTcpRouter(string $name, string $rule, string $serviceName): TcpRouter {
106 | if (!isset($this->config['TR'][$name])) {
107 | $this->config['TR'][$name] = (new TcpRouter())
108 | ->setName($name)
109 | ->setRule($rule)
110 | ->setService($serviceName);
111 | }
112 | return $this->config['TR'][$name];
113 | }
114 |
115 | /**
116 | * @param string $name
117 | * @param string $url
118 | * @return UdpService
119 | */
120 | public function setUdpService(string $name, string $url): UdpService {
121 | if (!isset($this->config['US'][$name])) {
122 | $this->config['US'][$name] = (new UdpService())
123 | ->setName($name)
124 | ->setType(TcpService::LOADBALANCER)
125 | ->addServer($url);
126 | }
127 | return $this->config['US'][$name];
128 | }
129 |
130 | /**
131 | * @param string $name
132 | * @param string $rule
133 | * @param string $serviceName
134 | * @return UdpRouter
135 | */
136 | public function setUdpRouter(string $name, string $rule, string $serviceName): UdpRouter {
137 | if (!isset($this->config['UR'][$name])) {
138 | $this->config['UR'][$name] = (new UdpRouter())
139 | ->setName($name)
140 | ->setRule($rule)
141 | ->setService($serviceName);
142 | }
143 | return $this->config['UR'][$name];
144 | }
145 |
146 | /**
147 | * @return string
148 | */
149 | public function getJsonConfig(): string {
150 | $result = [];
151 |
152 | foreach ($this->config as $configType) {
153 | /**
154 | * @var $config ConfigObject
155 | */
156 | foreach ($configType as $config) {
157 | if (!$config instanceof ConfigObject) {
158 | var_dump($config);
159 | exit;
160 | }
161 | $transport = $config->getTraefikTransport();
162 | $classType = $config->getTraefikType();
163 | $name = $config->getName();
164 | $data = $config->getData();
165 |
166 | if (!isset($result[$transport])) {
167 | $result[$transport] = [];
168 | }
169 | if (!isset($result[$transport][$classType])) {
170 | $result[$transport][$classType] = [];
171 | }
172 | if (!isset($result[$transport][$classType][$name])) {
173 | $result[$transport][$classType][$name] = [];
174 | }
175 | $result[$transport][$classType][$name] = $data;
176 | }
177 | }
178 |
179 | return json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/tests/config/fullConfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "udp": {
3 | "services": {
4 | "UDPService01": {
5 | "loadBalancer": {
6 | "servers": [
7 | {
8 | "address": "foobar"
9 | },
10 | {
11 | "address": "foobar"
12 | }
13 | ]
14 | }
15 | }
16 | },
17 | "routers": {
18 | "UDPRouter0": {
19 | "entryPoints": [
20 | "foobar",
21 | "foobar"
22 | ],
23 | "service": "foobar"
24 | },
25 | "UDPRouter1": {
26 | "entryPoints": [
27 | "foobar",
28 | "foobar"
29 | ],
30 | "service": "foobar"
31 | }
32 | }
33 | },
34 | "http": {
35 | "services": {
36 | "Service01": {
37 | "loadBalancer": {
38 | "passHostHeader": true,
39 | "servers": [
40 | {
41 | "url": "foobar"
42 | },
43 | {
44 | "url": "foobar"
45 | }
46 | ]
47 | }
48 | }
49 | },
50 | "routers": {
51 | "Router0": {
52 | "priority": 42,
53 | "entryPoints": [
54 | "foobar",
55 | "foobar"
56 | ],
57 | "service": "foobar",
58 | "middlewares": [
59 | "foobar",
60 | "foobar"
61 | ],
62 | "rule": "foobar"
63 | },
64 | "Router1": {
65 | "priority": 42,
66 | "entryPoints": [
67 | "foobar",
68 | "foobar"
69 | ],
70 | "service": "foobar",
71 | "middlewares": [
72 | "foobar",
73 | "foobar"
74 | ],
75 | "rule": "foobar"
76 | }
77 | },
78 | "middlewares": {
79 | "Middleware22": {
80 | "stripPrefixRegex": {
81 | "regex": [
82 | "foobar",
83 | "foobar"
84 | ]
85 | }
86 | },
87 | "Middleware00": {
88 | "addPrefix": {
89 | "prefix": "foobar"
90 | }
91 | },
92 | "Middleware01": {
93 | "basicAuth": {
94 | "removeHeader": true,
95 | "realm": "foobar",
96 | "usersFile": "foobar",
97 | "headerField": "foobar",
98 | "users": [
99 | "foobar",
100 | "foobar"
101 | ]
102 | }
103 | },
104 | "Middleware02": {
105 | "buffering": {
106 | "memRequestBodyBytes": 42,
107 | "maxRequestBodyBytes": 42,
108 | "memResponseBodyBytes": 42,
109 | "maxResponseBodyBytes": 42,
110 | "retryExpression": "foobar"
111 | }
112 | },
113 | "Middleware03": {
114 | "chain": {
115 | "middlewares": [
116 | "foobar",
117 | "foobar"
118 | ]
119 | }
120 | },
121 | "Middleware06": {
122 | "contentType": {
123 | "autoDetect": true
124 | }
125 | },
126 | "Middleware08": {
127 | "errors": {
128 | "status": [
129 | "foobar",
130 | "foobar"
131 | ],
132 | "query": "foobar",
133 | "service": "foobar"
134 | }
135 | },
136 | "Middleware09": {
137 | "forwardAuth": {
138 | "tls": {
139 | "cert": "foobar",
140 | "ca": "foobar",
141 | "caOptional": true,
142 | "insecureSkipVerify": true,
143 | "key": "foobar"
144 | },
145 | "trustForwardHeader": true,
146 | "authResponseHeaders": [
147 | "foobar",
148 | "foobar"
149 | ],
150 | "address": "foobar"
151 | }
152 | },
153 | "Middleware19": {
154 | "replacePathRegex": {
155 | "regex": "foobar",
156 | "replacement": "foobar"
157 | }
158 | },
159 | "Middleware18": {
160 | "replacePath": {
161 | "path": "foobar"
162 | }
163 | },
164 | "Middleware17": {
165 | "redirectScheme": {
166 | "scheme": "foobar",
167 | "permanent": true,
168 | "port": "foobar"
169 | }
170 | },
171 | "Middleware16": {
172 | "redirectRegex": {
173 | "regex": "foobar",
174 | "permanent": true,
175 | "replacement": "foobar"
176 | }
177 | },
178 | "Middleware15": {
179 | "rateLimit": {
180 | "average": 42,
181 | "burst": 42,
182 | "period": 42,
183 | "sourceCriterion": {
184 | "ipStrategy": {
185 | "depth": 42,
186 | "excludedIPs": [
187 | "foobar",
188 | "foobar"
189 | ]
190 | },
191 | "requestHeaderName": "foobar",
192 | "requestHost": true
193 | }
194 | }
195 | },
196 | "Middleware21": {
197 | "stripPrefix": {
198 | "prefixes": [
199 | "foobar",
200 | "foobar"
201 | ],
202 | "forceSlash": true
203 | }
204 | },
205 | "Middleware13": {
206 | "passTLSClientCert": {
207 | "info": {
208 | "sans": true,
209 | "notBefore": true,
210 | "issuer": {
211 | "province": true,
212 | "organization": true,
213 | "domainComponent": true,
214 | "locality": true,
215 | "country": true,
216 | "serialNumber": true,
217 | "commonName": true
218 | },
219 | "serialNumber": true,
220 | "subject": {
221 | "province": true,
222 | "organization": true,
223 | "domainComponent": true,
224 | "locality": true,
225 | "country": true,
226 | "serialNumber": true,
227 | "commonName": true
228 | },
229 | "notAfter": true
230 | },
231 | "pem": true
232 | }
233 | },
234 | "Middleware12": {
235 | "inFlightReq": {
236 | "amount": 42,
237 | "sourceCriterion": {
238 | "ipStrategy": {
239 | "depth": 42,
240 | "excludedIPs": [
241 | "foobar",
242 | "foobar"
243 | ]
244 | },
245 | "requestHeaderName": "foobar",
246 | "requestHost": true
247 | }
248 | }
249 | },
250 | "Middleware11": {
251 | "ipWhiteList": {
252 | "ipStrategy": {
253 | "depth": 42,
254 | "excludedIPs": [
255 | "foobar",
256 | "foobar"
257 | ]
258 | },
259 | "sourceRange": [
260 | "foobar",
261 | "foobar"
262 | ]
263 | }
264 | },
265 | "Middleware10": {
266 | "headers": {
267 | "stsIncludeSubdomains": true,
268 | "addVaryHeader": true,
269 | "customRequestHeaders": {
270 | "name0": "foobar",
271 | "name1": "foobar"
272 | },
273 | "accessControlAllowOriginList": [
274 | "foobar",
275 | "foobar"
276 | ],
277 | "sslProxyHeaders": {
278 | "name0": "foobar",
279 | "name1": "foobar"
280 | },
281 | "referrerPolicy": "foobar",
282 | "accessControlAllowMethods": [
283 | "foobar",
284 | "foobar"
285 | ],
286 | "accessControlAllowOrigin": "foobar",
287 | "sslTemporaryRedirect": true,
288 | "contentTypeNosniff": true,
289 | "stsSeconds": 42,
290 | "sslRedirect": true,
291 | "accessControlAllowCredentials": true,
292 | "sslHost": "foobar",
293 | "browserXssFilter": true,
294 | "contentSecurityPolicy": "foobar",
295 | "hostsProxyHeaders": [
296 | "foobar",
297 | "foobar"
298 | ],
299 | "accessControlAllowHeaders": [
300 | "foobar",
301 | "foobar"
302 | ],
303 | "sslForceHost": true,
304 | "customResponseHeaders": {
305 | "name0": "foobar",
306 | "name1": "foobar"
307 | },
308 | "forceSTSHeader": true,
309 | "publicKey": "foobar",
310 | "frameDeny": true,
311 | "allowedHosts": [
312 | "foobar",
313 | "foobar"
314 | ],
315 | "isDevelopment": true,
316 | "customBrowserXSSValue": "foobar",
317 | "accessControlMaxAge": 42,
318 | "customFrameOptionsValue": "foobar",
319 | "stsPreload": true,
320 | "accessControlExposeHeaders": [
321 | "foobar",
322 | "foobar"
323 | ],
324 | "featurePolicy": "foobar"
325 | }
326 | },
327 | "Middleware04": {
328 | "circuitBreaker": {
329 | "expression": "foobar"
330 | }
331 | },
332 | "Middleware05": {
333 | "compress": {
334 | "excludedContentTypes": [
335 | "foobar",
336 | "foobar"
337 | ]
338 | }
339 | },
340 | "Middleware07": {
341 | "digestAuth": {
342 | "removeHeader": true,
343 | "realm": "foobar",
344 | "usersFile": "foobar",
345 | "headerField": "foobar",
346 | "users": [
347 | "foobar",
348 | "foobar"
349 | ]
350 | }
351 | },
352 | "Middleware20": {
353 | "retry": {
354 | "attempts": 42
355 | }
356 | }
357 | }
358 | },
359 | "tcp": {
360 | "services": {
361 | "TCPService01": {
362 | "loadBalancer": {
363 | "terminationDelay": 42,
364 | "servers": [
365 | {
366 | "address": "foobar"
367 | },
368 | {
369 | "address": "foobar"
370 | }
371 | ]
372 | }
373 | }
374 | },
375 | "routers": {
376 | "TCPRouter0": {
377 | "entryPoints": [
378 | "foobar",
379 | "foobar"
380 | ],
381 | "service": "foobar",
382 | "rule": "foobar"
383 | },
384 | "TCPRouter1": {
385 | "entryPoints": [
386 | "foobar",
387 | "foobar"
388 | ],
389 | "service": "foobar",
390 | "rule": "foobar"
391 | }
392 | }
393 | }
394 | }
395 |
--------------------------------------------------------------------------------
/src/Traefik/Middleware/Config/Headers.php:
--------------------------------------------------------------------------------
1 | stsIncludeSubdomains ?? null;
53 | }
54 |
55 | /**
56 | * @param bool $stsIncludeSubdomains
57 | * @return $this
58 | */
59 | public function setStsIncludeSubdomains(bool $stsIncludeSubdomains): self {
60 | $this->stsIncludeSubdomains = $stsIncludeSubdomains;
61 | return $this;
62 | }
63 |
64 | /**
65 | * @return bool|null
66 | */
67 | public function getAddVaryHeader(): ?bool {
68 | return $this->addVaryHeader ?? null;
69 | }
70 |
71 | /**
72 | * @param bool $addVaryHeader
73 | * @return $this
74 | */
75 | public function setAddVaryHeader(bool $addVaryHeader): self {
76 | $this->addVaryHeader = $addVaryHeader;
77 | return $this;
78 | }
79 |
80 | /**
81 | * @return string
82 | */
83 | public function getAccessControlAllowOrigin(): ?string {
84 | return $this->accessControlAllowOrigin ?? null;
85 | }
86 |
87 | /**
88 | * @param string $accessControlAllowOrigin
89 | * @return $this
90 | */
91 | public function setAccessControlAllowOrigin(string $accessControlAllowOrigin): self {
92 | $this->accessControlAllowOrigin = $accessControlAllowOrigin;
93 | return $this;
94 | }
95 |
96 | /**
97 | * @return bool|null
98 | */
99 | public function getSslTemporaryRedirect(): ?bool {
100 | return $this->sslTemporaryRedirect ?? null;
101 | }
102 |
103 | /**
104 | * @param bool $sslTemporaryRedirect
105 | * @return $this
106 | */
107 | public function setSslTemporaryRedirect(bool $sslTemporaryRedirect): self {
108 | $this->sslTemporaryRedirect = $sslTemporaryRedirect;
109 | return $this;
110 | }
111 |
112 | /**
113 | * @return bool|null
114 | */
115 | public function getContentTypeNosniff(): ?bool {
116 | return $this->contentTypeNosniff ?? null;
117 | }
118 |
119 | /**
120 | * @param bool $contentTypeNosniff
121 | * @return $this
122 | */
123 | public function setContentTypeNosniff(bool $contentTypeNosniff): self {
124 | $this->contentTypeNosniff = $contentTypeNosniff;
125 | return $this;
126 | }
127 |
128 | /**
129 | * @return int
130 | */
131 | public function getStsSeconds(): ?int {
132 | return $this->stsSeconds ?? null;
133 | }
134 |
135 | /**
136 | * @param int $stsSeconds
137 | * @return $this
138 | */
139 | public function setStsSeconds(int $stsSeconds): self {
140 | $this->stsSeconds = $stsSeconds;
141 | return $this;
142 | }
143 |
144 | /**
145 | * @return bool|null
146 | */
147 | public function getSslRedirect(): ?bool {
148 | return $this->sslRedirect ?? null;
149 | }
150 |
151 | /**
152 | * @param bool $sslRedirect
153 | * @return $this
154 | */
155 | public function setSslRedirect(bool $sslRedirect): self {
156 | $this->sslRedirect = $sslRedirect;
157 | return $this;
158 | }
159 |
160 | /**
161 | * @return bool|null
162 | */
163 | public function getAccessControlAllowCredentials(): ?bool {
164 | return $this->accessControlAllowCredentials ?? null;
165 | }
166 |
167 | /**
168 | * @param bool $accessControlAllowCredentials
169 | * @return $this
170 | */
171 | public function setAccessControlAllowCredentials(bool $accessControlAllowCredentials): self {
172 | $this->accessControlAllowCredentials = $accessControlAllowCredentials;
173 | return $this;
174 | }
175 |
176 | /**
177 | * @return string
178 | */
179 | public function getSslHost(): ?string {
180 | return $this->sslHost ?? null;
181 | }
182 |
183 | /**
184 | * @param string $sslHost
185 | * @return $this
186 | */
187 | public function setSslHost(string $sslHost): self {
188 | $this->sslHost = $sslHost;
189 | return $this;
190 | }
191 |
192 | /**
193 | * @return bool|null
194 | */
195 | public function getBrowserXssFilter(): ?bool {
196 | return $this->browserXssFilter ?? null;
197 | }
198 |
199 | /**
200 | * @param bool $browserXssFilter
201 | * @return $this
202 | */
203 | public function setBrowserXssFilter(bool $browserXssFilter): self {
204 | $this->browserXssFilter = $browserXssFilter;
205 | return $this;
206 | }
207 |
208 | /**
209 | * @return string
210 | */
211 | public function getContentSecurityPolicy(): ?string {
212 | return $this->contentSecurityPolicy ?? null;
213 | }
214 |
215 | /**
216 | * @param string $contentSecurityPolicy
217 | * @return $this
218 | */
219 | public function setContentSecurityPolicy(string $contentSecurityPolicy): self {
220 | $this->contentSecurityPolicy = $contentSecurityPolicy;
221 | return $this;
222 | }
223 |
224 | /**
225 | * @return string
226 | */
227 | public function getReferrerPolicy(): ?string {
228 | return $this->referrerPolicy ?? null;
229 | }
230 |
231 | /**
232 | * @param string $referrerPolicy
233 | * @return $this
234 | */
235 | public function setReferrerPolicy(string $referrerPolicy): self {
236 | $this->referrerPolicy = $referrerPolicy;
237 | return $this;
238 | }
239 |
240 | /**
241 | * @return bool|null
242 | */
243 | public function getSslForceHost(): ?bool {
244 | return $this->sslForceHost ?? null;
245 | }
246 |
247 | /**
248 | * @param bool $sslForceHost
249 | * @return $this
250 | */
251 | public function setSslForceHost(bool $sslForceHost): self {
252 | $this->sslForceHost = $sslForceHost;
253 | return $this;
254 | }
255 |
256 | /**
257 | * @return bool|null
258 | */
259 | public function getForceSTSHeader(): ?bool {
260 | return $this->forceSTSHeader ?? null;
261 | }
262 |
263 | /**
264 | * @param bool $forceSTSHeader
265 | * @return $this
266 | */
267 | public function setForceSTSHeader(bool $forceSTSHeader): self {
268 | $this->forceSTSHeader = $forceSTSHeader;
269 | return $this;
270 | }
271 |
272 | /**
273 | * @return string
274 | */
275 | public function getPublicKey(): ?string {
276 | return $this->publicKey ?? null;
277 | }
278 |
279 | /**
280 | * @param string $publicKey
281 | * @return $this
282 | */
283 | public function setPublicKey(string $publicKey): self {
284 | $this->publicKey = $publicKey;
285 | return $this;
286 | }
287 |
288 | /**
289 | * @return bool|null
290 | */
291 | public function getFrameDeny(): ?bool {
292 | return $this->frameDeny ?? null;
293 | }
294 |
295 | /**
296 | * @param bool $frameDeny
297 | * @return $this
298 | */
299 | public function setFrameDeny(bool $frameDeny): self {
300 | $this->frameDeny = $frameDeny;
301 | return $this;
302 | }
303 |
304 | /**
305 | * @return bool|null
306 | */
307 | public function getDevelopment(): ?bool {
308 | return $this->isDevelopment ?? null;
309 | }
310 |
311 | /**
312 | * @param bool $isDevelopment
313 | * @return $this
314 | */
315 | public function setIsDevelopment(bool $isDevelopment): self {
316 | $this->isDevelopment = $isDevelopment;
317 | return $this;
318 | }
319 |
320 | /**
321 | * @return string
322 | */
323 | public function getCustomBrowserXSSValue(): ?string {
324 | return $this->customBrowserXSSValue ?? null;
325 | }
326 |
327 | /**
328 | * @param string $customBrowserXSSValue
329 | * @return $this
330 | */
331 | public function setCustomBrowserXSSValue(string $customBrowserXSSValue): self {
332 | $this->customBrowserXSSValue = $customBrowserXSSValue;
333 | return $this;
334 | }
335 |
336 | /**
337 | * @return int
338 | */
339 | public function getAccessControlMaxAge(): ?int {
340 | return $this->accessControlMaxAge ?? null;
341 | }
342 |
343 | /**
344 | * @param int $accessControlMaxAge
345 | * @return $this
346 | */
347 | public function setAccessControlMaxAge(int $accessControlMaxAge): self {
348 | $this->accessControlMaxAge = $accessControlMaxAge;
349 | return $this;
350 | }
351 |
352 | /**
353 | * @return string
354 | */
355 | public function getCustomFrameOptionsValue(): ?string {
356 | return $this->customFrameOptionsValue ?? null;
357 | }
358 |
359 | /**
360 | * @param string $customFrameOptionsValue
361 | * @return $this
362 | */
363 | public function setCustomFrameOptionsValue(string $customFrameOptionsValue): self {
364 | $this->customFrameOptionsValue = $customFrameOptionsValue;
365 | return $this;
366 | }
367 |
368 | /**
369 | * @return bool|null
370 | */
371 | public function getStsPreload(): ?bool {
372 | return $this->stsPreload ?? null;
373 | }
374 |
375 | /**
376 | * @param bool $stsPreload
377 | * @return $this
378 | */
379 | public function setStsPreload(bool $stsPreload): self {
380 | $this->stsPreload = $stsPreload;
381 | return $this;
382 | }
383 |
384 | /**
385 | * @return string
386 | */
387 | public function getFeaturePolicy(): ?string {
388 | return $this->featurePolicy ?? null;
389 | }
390 |
391 | /**
392 | * @param string $featurePolicy
393 | * @return $this
394 | */
395 | public function setFeaturePolicy(string $featurePolicy): self {
396 | $this->featurePolicy = $featurePolicy;
397 | return $this;
398 | }
399 |
400 | /**
401 | * @return array
402 | */
403 | public function getAccessControlAllowOriginList(): ?array {
404 | return $this->accessControlAllowOriginList ?? null;
405 | }
406 |
407 | /**
408 | * @param string $accessControlAllowOriginLis
409 | * @return $this
410 | */
411 | public function addAccessControlAllowOriginList(string $accessControlAllowOriginLis): self {
412 | $this->accessControlAllowOriginList[] = $accessControlAllowOriginLis;
413 | return $this;
414 | }
415 |
416 | /**
417 | * @return array
418 | */
419 | public function getAccessControlAllowMethods(): ?array {
420 | return $this->accessControlAllowMethods ?? null;
421 | }
422 |
423 | /**
424 | * @param string $accessControlAllowMethod
425 | * @return $this
426 | */
427 | public function addAccessControlAllowMethods(string $accessControlAllowMethod): self {
428 | $this->accessControlAllowMethods[] = $accessControlAllowMethod;
429 | return $this;
430 | }
431 |
432 | /**
433 | * @return array
434 | */
435 | public function getHostsProxyHeaders(): ?array {
436 | return $this->hostsProxyHeaders ?? null;
437 | }
438 |
439 | /**
440 | * @param string $hostsProxyHeader
441 | * @return $this
442 | */
443 | public function addHostsProxyHeaders(string $hostsProxyHeader): self {
444 | $this->hostsProxyHeaders[] = $hostsProxyHeader;
445 | return $this;
446 | }
447 |
448 | /**
449 | * @return array
450 | */
451 | public function getAccessControlAllowHeaders(): ?array {
452 | return $this->accessControlAllowHeaders ?? null;
453 | }
454 |
455 | /**
456 | * @param string $accessControlAllowHeader
457 | * @return $this
458 | */
459 | public function addAccessControlAllowHeaders(string $accessControlAllowHeader): self {
460 | $this->accessControlAllowHeaders[] = $accessControlAllowHeader;
461 | return $this;
462 | }
463 |
464 | /**
465 | * @return array
466 | */
467 | public function getAllowedHosts(): ?array {
468 | return $this->allowedHosts ?? null;
469 | }
470 |
471 | /**
472 | * @param string $allowedHost
473 | * @return $this
474 | */
475 | public function addAllowedHosts(string $allowedHost): self {
476 | $this->allowedHosts[] = $allowedHost;
477 | return $this;
478 | }
479 |
480 | /**
481 | * @return array
482 | */
483 | public function getAccessControlExposeHeaders(): ?array {
484 | return $this->accessControlExposeHeaders ?? null;
485 | }
486 |
487 | /**
488 | * @param string $accessControlExposeHeader
489 | * @return $this
490 | */
491 | public function addAccessControlExposeHeaders(string $accessControlExposeHeader): self {
492 | $this->accessControlExposeHeaders[] = $accessControlExposeHeader;
493 | return $this;
494 | }
495 |
496 | /**
497 | * @return array
498 | */
499 | public function getCustomRequestHeaders(): ?array {
500 | return $this->customRequestHeaders ?? null;
501 | }
502 |
503 | /**
504 | * @param string $key
505 | * @param string $value
506 | * @return $this
507 | */
508 | public function addCustomRequestHeaders(string $key, string $value): self {
509 | $this->customRequestHeaders[$key] = $value;
510 | return $this;
511 | }
512 |
513 | /**
514 | * @return array
515 | */
516 | public function getCustomResponseHeaders(): ?array {
517 | return $this->customResponseHeaders ?? null;
518 | }
519 |
520 | /**
521 | * @param string $key
522 | * @param string $value
523 | * @return $this
524 | */
525 | public function addCustomResponseHeaders(string $key, string $value): self {
526 | $this->customResponseHeaders[$key] = $value;
527 | return $this;
528 | }
529 |
530 | /**
531 | * @return array
532 | */
533 | public function getSslProxyHeaders(): ?array {
534 | return $this->sslProxyHeaders ?? null;
535 | }
536 |
537 | /**
538 | * @param string $key
539 | * @param string $value
540 | * @return $this
541 | */
542 | public function addSslProxyHeaders(string $key, string $value): self {
543 | $this->sslProxyHeaders[$key] = $value;
544 | return $this;
545 | }
546 | }
547 |
--------------------------------------------------------------------------------
/tests/config/fullConfig copy.json:
--------------------------------------------------------------------------------
1 | {
2 | "tls": {
3 | "certificates": [
4 | {
5 | "certFile": "foobar",
6 | "keyFile": "foobar",
7 | "stores": [
8 | "foobar",
9 | "foobar"
10 | ]
11 | },
12 | {
13 | "certFile": "foobar",
14 | "keyFile": "foobar",
15 | "stores": [
16 | "foobar",
17 | "foobar"
18 | ]
19 | }
20 | ],
21 | "stores": {
22 | "Store1": {
23 | "defaultCertificate": {
24 | "certFile": "foobar",
25 | "keyFile": "foobar"
26 | }
27 | },
28 | "Store0": {
29 | "defaultCertificate": {
30 | "certFile": "foobar",
31 | "keyFile": "foobar"
32 | }
33 | }
34 | },
35 | "options": {
36 | "Options0": {
37 | "preferServerCipherSuites": true,
38 | "clientAuth": {
39 | "caFiles": [
40 | "foobar",
41 | "foobar"
42 | ],
43 | "clientAuthType": "foobar"
44 | },
45 | "sniStrict": true,
46 | "maxVersion": "foobar",
47 | "minVersion": "foobar",
48 | "cipherSuites": [
49 | "foobar",
50 | "foobar"
51 | ],
52 | "curvePreferences": [
53 | "foobar",
54 | "foobar"
55 | ]
56 | },
57 | "Options1": {
58 | "preferServerCipherSuites": true,
59 | "clientAuth": {
60 | "caFiles": [
61 | "foobar",
62 | "foobar"
63 | ],
64 | "clientAuthType": "foobar"
65 | },
66 | "sniStrict": true,
67 | "maxVersion": "foobar",
68 | "minVersion": "foobar",
69 | "cipherSuites": [
70 | "foobar",
71 | "foobar"
72 | ],
73 | "curvePreferences": [
74 | "foobar",
75 | "foobar"
76 | ]
77 | }
78 | }
79 | },
80 | "udp": {
81 | "services": {
82 | "UDPService02": {
83 | "weighted": {
84 | "services": [
85 | {
86 | "name": "foobar",
87 | "weight": 42
88 | },
89 | {
90 | "name": "foobar",
91 | "weight": 42
92 | }
93 | ]
94 | }
95 | },
96 | "UDPService01": {
97 | "loadBalancer": {
98 | "servers": [
99 | {
100 | "address": "foobar"
101 | },
102 | {
103 | "address": "foobar"
104 | }
105 | ]
106 | }
107 | }
108 | },
109 | "routers": {
110 | "UDPRouter0": {
111 | "entryPoints": [
112 | "foobar",
113 | "foobar"
114 | ],
115 | "service": "foobar"
116 | },
117 | "UDPRouter1": {
118 | "entryPoints": [
119 | "foobar",
120 | "foobar"
121 | ],
122 | "service": "foobar"
123 | }
124 | }
125 | },
126 | "http": {
127 | "services": {
128 | "Service01": {
129 | "loadBalancer": {
130 | "passHostHeader": true,
131 |
132 | "healthCheck": {
133 | "hostname": "foobar",
134 | "interval": "foobar",
135 | "headers": {
136 | "name0": "foobar",
137 | "name1": "foobar"
138 | },
139 | "followRedirects": true,
140 | "timeout": "foobar",
141 | "path": "foobar",
142 | "scheme": "foobar",
143 | "port": 42
144 | },
145 | "sticky": {
146 | "cookie": {
147 | "secure": true,
148 | "name": "foobar",
149 | "httpOnly": true,
150 | "sameSite": "foobar"
151 | }
152 | },
153 | "responseForwarding": {
154 | "flushInterval": "foobar"
155 | },
156 | "servers": [
157 | {
158 | "url": "foobar"
159 | },
160 | {
161 | "url": "foobar"
162 | }
163 | ]
164 | }
165 | },
166 | "Service02": {
167 | "mirroring": {
168 | "maxBodySize": 42,
169 | "service": "foobar",
170 | "mirrors": [
171 | {
172 | "percent": 42,
173 | "name": "foobar"
174 | },
175 | {
176 | "percent": 42,
177 | "name": "foobar"
178 | }
179 | ]
180 | }
181 | },
182 | "Service03": {
183 | "weighted": {
184 | "services": [
185 | {
186 | "name": "foobar",
187 | "weight": 42
188 | },
189 | {
190 | "name": "foobar",
191 | "weight": 42
192 | }
193 | ],
194 | "sticky": {
195 | "cookie": {
196 | "secure": true,
197 | "name": "foobar",
198 | "httpOnly": true,
199 | "sameSite": "foobar"
200 | }
201 | }
202 | }
203 | }
204 | },
205 | "routers": {
206 | "Router0": {
207 | "tls": {
208 | "domains": [
209 | {
210 | "main": "foobar",
211 | "sans": [
212 | "foobar",
213 | "foobar"
214 | ]
215 | },
216 | {
217 | "main": "foobar",
218 | "sans": [
219 | "foobar",
220 | "foobar"
221 | ]
222 | }
223 | ],
224 | "certResolver": "foobar",
225 | "options": "foobar"
226 | },
227 | "priority": 42,
228 | "entryPoints": [
229 | "foobar",
230 | "foobar"
231 | ],
232 | "service": "foobar",
233 | "middlewares": [
234 | "foobar",
235 | "foobar"
236 | ],
237 | "rule": "foobar"
238 | },
239 | "Router1": {
240 | "tls": {
241 | "domains": [
242 | {
243 | "main": "foobar",
244 | "sans": [
245 | "foobar",
246 | "foobar"
247 | ]
248 | },
249 | {
250 | "main": "foobar",
251 | "sans": [
252 | "foobar",
253 | "foobar"
254 | ]
255 | }
256 | ],
257 | "certResolver": "foobar",
258 | "options": "foobar"
259 | },
260 | "priority": 42,
261 | "entryPoints": [
262 | "foobar",
263 | "foobar"
264 | ],
265 | "service": "foobar",
266 | "middlewares": [
267 | "foobar",
268 | "foobar"
269 | ],
270 | "rule": "foobar"
271 | }
272 | },
273 | "middlewares": {
274 | "Middleware14": {
275 | "plugin": {
276 | "PluginConf": {
277 | "foo": "bar"
278 | }
279 | }
280 | },
281 | "Middleware22": {
282 | "stripPrefixRegex": {
283 | "regex": [
284 | "foobar",
285 | "foobar"
286 | ]
287 | }
288 | },
289 | "Middleware00": {
290 | "addPrefix": {
291 | "prefix": "foobar"
292 | }
293 | },
294 | "Middleware01": {
295 | "basicAuth": {
296 | "removeHeader": true,
297 | "realm": "foobar",
298 | "usersFile": "foobar",
299 | "headerField": "foobar",
300 | "users": [
301 | "foobar",
302 | "foobar"
303 | ]
304 | }
305 | },
306 | "Middleware02": {
307 | "buffering": {
308 | "memRequestBodyBytes": 42,
309 | "maxRequestBodyBytes": 42,
310 | "memResponseBodyBytes": 42,
311 | "maxResponseBodyBytes": 42,
312 | "retryExpression": "foobar"
313 | }
314 | },
315 | "Middleware03": {
316 | "chain": {
317 | "middlewares": [
318 | "foobar",
319 | "foobar"
320 | ]
321 | }
322 | },
323 | "Middleware06": {
324 | "contentType": {
325 | "autoDetect": true
326 | }
327 | },
328 | "Middleware08": {
329 | "errors": {
330 | "status": [
331 | "foobar",
332 | "foobar"
333 | ],
334 | "query": "foobar",
335 | "service": "foobar"
336 | }
337 | },
338 | "Middleware09": {
339 | "forwardAuth": {
340 | "tls": {
341 | "cert": "foobar",
342 | "ca": "foobar",
343 | "caOptional": true,
344 | "insecureSkipVerify": true,
345 | "key": "foobar"
346 | },
347 | "trustForwardHeader": true,
348 | "authResponseHeaders": [
349 | "foobar",
350 | "foobar"
351 | ],
352 | "address": "foobar"
353 | }
354 | },
355 | "Middleware19": {
356 | "replacePathRegex": {
357 | "regex": "foobar",
358 | "replacement": "foobar"
359 | }
360 | },
361 | "Middleware18": {
362 | "replacePath": {
363 | "path": "foobar"
364 | }
365 | },
366 | "Middleware17": {
367 | "redirectScheme": {
368 | "scheme": "foobar",
369 | "permanent": true,
370 | "port": "foobar"
371 | }
372 | },
373 | "Middleware16": {
374 | "redirectRegex": {
375 | "regex": "foobar",
376 | "permanent": true,
377 | "replacement": "foobar"
378 | }
379 | },
380 | "Middleware15": {
381 | "rateLimit": {
382 | "average": 42,
383 | "burst": 42,
384 | "period": 42,
385 | "sourceCriterion": {
386 | "ipStrategy": {
387 | "depth": 42,
388 | "excludedIPs": [
389 | "foobar",
390 | "foobar"
391 | ]
392 | },
393 | "requestHeaderName": "foobar",
394 | "requestHost": true
395 | }
396 | }
397 | },
398 | "Middleware21": {
399 | "stripPrefix": {
400 | "prefixes": [
401 | "foobar",
402 | "foobar"
403 | ],
404 | "forceSlash": true
405 | }
406 | },
407 | "Middleware13": {
408 | "passTLSClientCert": {
409 | "info": {
410 | "sans": true,
411 | "notBefore": true,
412 | "issuer": {
413 | "province": true,
414 | "organization": true,
415 | "domainComponent": true,
416 | "locality": true,
417 | "country": true,
418 | "serialNumber": true,
419 | "commonName": true
420 | },
421 | "serialNumber": true,
422 | "subject": {
423 | "province": true,
424 | "organization": true,
425 | "domainComponent": true,
426 | "locality": true,
427 | "country": true,
428 | "serialNumber": true,
429 | "commonName": true
430 | },
431 | "notAfter": true
432 | },
433 | "pem": true
434 | }
435 | },
436 | "Middleware12": {
437 | "inFlightReq": {
438 | "amount": 42,
439 | "sourceCriterion": {
440 | "ipStrategy": {
441 | "depth": 42,
442 | "excludedIPs": [
443 | "foobar",
444 | "foobar"
445 | ]
446 | },
447 | "requestHeaderName": "foobar",
448 | "requestHost": true
449 | }
450 | }
451 | },
452 | "Middleware11": {
453 | "ipWhiteList": {
454 | "ipStrategy": {
455 | "depth": 42,
456 | "excludedIPs": [
457 | "foobar",
458 | "foobar"
459 | ]
460 | },
461 | "sourceRange": [
462 | "foobar",
463 | "foobar"
464 | ]
465 | }
466 | },
467 | "Middleware10": {
468 | "headers": {
469 | "stsIncludeSubdomains": true,
470 | "addVaryHeader": true,
471 | "customRequestHeaders": {
472 | "name0": "foobar",
473 | "name1": "foobar"
474 | },
475 | "accessControlAllowOriginList": [
476 | "foobar",
477 | "foobar"
478 | ],
479 | "sslProxyHeaders": {
480 | "name0": "foobar",
481 | "name1": "foobar"
482 | },
483 | "referrerPolicy": "foobar",
484 | "accessControlAllowMethods": [
485 | "foobar",
486 | "foobar"
487 | ],
488 | "accessControlAllowOrigin": "foobar",
489 | "sslTemporaryRedirect": true,
490 | "contentTypeNosniff": true,
491 | "stsSeconds": 42,
492 | "sslRedirect": true,
493 | "accessControlAllowCredentials": true,
494 | "sslHost": "foobar",
495 | "browserXssFilter": true,
496 | "contentSecurityPolicy": "foobar",
497 | "hostsProxyHeaders": [
498 | "foobar",
499 | "foobar"
500 | ],
501 | "accessControlAllowHeaders": [
502 | "foobar",
503 | "foobar"
504 | ],
505 | "sslForceHost": true,
506 | "customResponseHeaders": {
507 | "name0": "foobar",
508 | "name1": "foobar"
509 | },
510 | "forceSTSHeader": true,
511 | "publicKey": "foobar",
512 | "frameDeny": true,
513 | "allowedHosts": [
514 | "foobar",
515 | "foobar"
516 | ],
517 | "isDevelopment": true,
518 | "customBrowserXSSValue": "foobar",
519 | "accessControlMaxAge": 42,
520 | "customFrameOptionsValue": "foobar",
521 | "stsPreload": true,
522 | "accessControlExposeHeaders": [
523 | "foobar",
524 | "foobar"
525 | ],
526 | "featurePolicy": "foobar"
527 | }
528 | },
529 | "Middleware04": {
530 | "circuitBreaker": {
531 | "expression": "foobar"
532 | }
533 | },
534 | "Middleware05": {
535 | "compress": {
536 | "excludedContentTypes": [
537 | "foobar",
538 | "foobar"
539 | ]
540 | }
541 | },
542 | "Middleware07": {
543 | "digestAuth": {
544 | "removeHeader": true,
545 | "realm": "foobar",
546 | "usersFile": "foobar",
547 | "headerField": "foobar",
548 | "users": [
549 | "foobar",
550 | "foobar"
551 | ]
552 | }
553 | },
554 | "Middleware20": {
555 | "retry": {
556 | "attempts": 42
557 | }
558 | }
559 | }
560 | },
561 | "tcp": {
562 | "services": {
563 | "TCPService02": {
564 | "weighted": {
565 | "services": [
566 | {
567 | "name": "foobar",
568 | "weight": 42
569 | },
570 | {
571 | "name": "foobar",
572 | "weight": 42
573 | }
574 | ]
575 | }
576 | },
577 | "TCPService01": {
578 | "loadBalancer": {
579 | "terminationDelay": 42,
580 | "servers": [
581 | {
582 | "address": "foobar"
583 | },
584 | {
585 | "address": "foobar"
586 | }
587 | ]
588 | }
589 | }
590 | },
591 | "routers": {
592 | "TCPRouter0": {
593 | "tls": {
594 | "domains": [
595 | {
596 | "main": "foobar",
597 | "sans": [
598 | "foobar",
599 | "foobar"
600 | ]
601 | },
602 | {
603 | "main": "foobar",
604 | "sans": [
605 | "foobar",
606 | "foobar"
607 | ]
608 | }
609 | ],
610 | "passthrough": true,
611 | "certResolver": "foobar",
612 | "options": "foobar"
613 | },
614 | "entryPoints": [
615 | "foobar",
616 | "foobar"
617 | ],
618 | "service": "foobar",
619 | "rule": "foobar"
620 | },
621 | "TCPRouter1": {
622 | "tls": {
623 | "domains": [
624 | {
625 | "main": "foobar",
626 | "sans": [
627 | "foobar",
628 | "foobar"
629 | ]
630 | },
631 | {
632 | "main": "foobar",
633 | "sans": [
634 | "foobar",
635 | "foobar"
636 | ]
637 | }
638 | ],
639 | "passthrough": true,
640 | "certResolver": "foobar",
641 | "options": "foobar"
642 | },
643 | "entryPoints": [
644 | "foobar",
645 | "foobar"
646 | ],
647 | "service": "foobar",
648 | "rule": "foobar"
649 | }
650 | }
651 | }
652 | }
653 |
--------------------------------------------------------------------------------
/tests/config/fullConfigTest.php:
--------------------------------------------------------------------------------
1 | setHttpService('Service01', 'foobar')->addServer('foobar');
54 | $config->setHttpRouter('Router0', 'foobar', 'foobar')
55 | ->setEntryPoints(['foobar', 'foobar'])
56 | ->setPriority(42)
57 | ->setMiddlewares(['foobar', 'foobar']);
58 | $config->setHttpRouter('Router1', 'foobar', 'foobar')
59 | ->setEntryPoints(['foobar', 'foobar'])
60 | ->setPriority(42)
61 | ->setMiddlewares(['foobar', 'foobar']);
62 |
63 | $config->setUdpService('UDPService01', 'foobar')->addServer('foobar');
64 | $config->setUdpRouter('UDPRouter0', '', 'foobar')->setEntryPoints(['foobar', 'foobar']);
65 | $config->setUdpRouter('UDPRouter1', '', 'foobar')->setEntryPoints(['foobar', 'foobar']);
66 |
67 | $config->setTcpService('TCPService01', 'foobar')
68 | ->setTerminationDelay(42)
69 | ->addServer('foobar');
70 | $config->setTcpRouter('TCPRouter0', 'foobar', 'foobar')
71 | ->setEntryPoints(['foobar', 'foobar']);
72 | $config->setTcpRouter('TCPRouter1', 'foobar', 'foobar')
73 | ->setEntryPoints(['foobar', 'foobar']);
74 |
75 | $config->addMiddleWare('Middleware00', $this->getMiddleware00Config());
76 | $config->addMiddleWare('Middleware01', $this->getMiddleware01Config());
77 | $config->addMiddleWare('Middleware02', $this->getMiddleware02Config());
78 | $config->addMiddleWare('Middleware03', $this->getMiddleware03Config());
79 | $config->addMiddleWare('Middleware04', $this->getMiddleware04Config());
80 | $config->addMiddleWare('Middleware05', $this->getMiddleware05Config());
81 | $config->addMiddleWare('Middleware06', $this->getMiddleware06Config());
82 | $config->addMiddleWare('Middleware07', $this->getMiddleware07Config());
83 | $config->addMiddleWare('Middleware08', $this->getMiddleware08Config());
84 | $config->addMiddleWare('Middleware09', $this->getMiddleware09Config());
85 | $config->addMiddleWare('Middleware10', $this->getMiddleware10Config());
86 | $config->addMiddleWare('Middleware11', $this->getMiddleware11Config());
87 | $config->addMiddleWare('Middleware12', $this->getMiddleware12Config());
88 | $config->addMiddleWare('Middleware13', $this->getMiddleware13Config());
89 | $config->addMiddleWare('Middleware15', $this->getMiddleware15Config());
90 | $config->addMiddleWare('Middleware16', $this->getMiddleware16Config());
91 | $config->addMiddleWare('Middleware17', $this->getMiddleware17Config());
92 | $config->addMiddleWare('Middleware18', $this->getMiddleware18Config());
93 | $config->addMiddleWare('Middleware19', $this->getMiddleware19Config());
94 | $config->addMiddleWare('Middleware20', $this->getMiddleware20Config());
95 | $config->addMiddleWare('Middleware21', $this->getMiddleware21Config());
96 | $config->addMiddleWare('Middleware22', $this->getMiddleware22Config());
97 |
98 | $phpConfig = json_decode($config->getJsonConfig(), true);
99 | $jsonConfig = json_decode(self::$jsonValidation, true);
100 |
101 | $this->validateArray($jsonConfig, $phpConfig);
102 | $this->validateArray($phpConfig, $jsonConfig);
103 | }
104 |
105 | private function getMiddleware00Config(): AddPrefixConfig
106 | {
107 | $prefixValue = 'foobar';
108 | return (new AddPrefixConfig())->setPrefix($prefixValue);
109 | }
110 |
111 | private function getMiddleware01Config(): BasicAuthConfig
112 | {
113 | $removeHeader = true;
114 | $realm = 'foobar';
115 | $usersFile = 'foobar';
116 | $headerField = 'foobar';
117 | $user1 = 'foobar';
118 | $user2 = 'foobar';
119 |
120 | return (new BasicAuthConfig())
121 | ->setUsersFile($usersFile)
122 | ->setRemoveHeader($removeHeader)
123 | ->setRealm($realm)
124 | ->setHeaderField($headerField)
125 | ->addUser($user1)
126 | ->addUser($user2);
127 | }
128 |
129 | private function getMiddleware02Config(): BufferingConfig
130 | {
131 | $memRequestBodyBytes = 42;
132 | $maxRequestBodyBytes = 42;
133 | $memResponseBodyBytes = 42;
134 | $maxResponseBodyBytes = 42;
135 | $retryExpression = 'foobar';
136 | return (new BufferingConfig())
137 | ->setRetryExpression($retryExpression)
138 | ->setMemResponseBodyBytes($memResponseBodyBytes)
139 | ->setMemRequestBodyBytes($memRequestBodyBytes)
140 | ->setMaxResponseBodyBytes($maxResponseBodyBytes)
141 | ->setMaxRequestBodyBytes($maxRequestBodyBytes);
142 | }
143 |
144 | private function getMiddleware03Config(): ChainConfig
145 | {
146 | $middleware1 = 'foobar';
147 | $middleware2 = 'foobar';
148 | return (new ChainConfig())
149 | ->addMiddleware($middleware1)
150 | ->addMiddleware($middleware2);
151 |
152 | }
153 |
154 | private function getMiddleware04Config(): CircuitBreakerConfig
155 | {
156 | $expression = 'foobar';
157 | return (new CircuitBreakerConfig())
158 | ->setExpression($expression);
159 | }
160 |
161 | private function getMiddleware05Config(): CompressConfig
162 | {
163 | $excludedContentType1 = 'foobar';
164 | $excludedContentType2 = 'foobar';
165 | return (new CompressConfig())
166 | ->addExcludedContentType($excludedContentType1)
167 | ->addExcludedContentType($excludedContentType2);
168 | }
169 |
170 | private function getMiddleware06Config(): ContentTypeConfig
171 | {
172 | $autoDetect = true;
173 |
174 | return (new ContentTypeConfig())
175 | ->setAutoDetect($autoDetect);
176 | }
177 |
178 | private function getMiddleware07Config(): DigestAuthConfig
179 | {
180 | $removeHeader = true;
181 | $realm = 'foobar';
182 | $usersFile = 'foobar';
183 | $headerField = 'foobar';
184 | $user1 = 'foobar';
185 | $user2 = 'foobar';
186 | return (new DigestAuthConfig())
187 | ->setHeaderField($headerField)
188 | ->setRealm($realm)
189 | ->setRemoveHeader($removeHeader)
190 | ->setUsersFile($usersFile)
191 | ->addUser($user1)
192 | ->addUser($user2);
193 | }
194 |
195 | private function getMiddleware08Config(): ErrorPageConfig
196 | {
197 | $status1 = 'foobar';
198 | $status2 = 'foobar';
199 | $query = 'foobar';
200 | $service = 'foobar';
201 | return (new ErrorPageConfig())
202 | ->setService($service)
203 | ->setQuery($query)
204 | ->addStatus($status1)
205 | ->addStatus($status2);
206 | }
207 |
208 | private function getMiddleware09Config(): ForwardAuthConfig
209 | {
210 |
211 | $tls_cert = 'foobar';
212 | $tls_ca = 'foobar';
213 | $tls_caOptional = true;
214 | $tls_insecureSkipVerify = true;
215 | $tls_key = 'foobar';
216 | $address = 'foobar';
217 | $trustForwardHeader = true;
218 |
219 | $authResponseHeader1 = 'foobar';
220 | $authResponseHeader2 = 'foobar';
221 |
222 | $tlsConfig = (new TlsConfig() )
223 | ->setCa($tls_ca)
224 | ->setCaOptional($tls_caOptional)
225 | ->setCert($tls_cert)
226 | ->setInsecureSkipVerify($tls_insecureSkipVerify)
227 | ->setKey($tls_key)
228 | ;
229 | return (new ForwardAuthConfig())
230 | ->setTls($tlsConfig)
231 | ->setAddress($address)
232 | ->setTrustForwardHeader($trustForwardHeader)
233 | ->addAuthResponseHeaders($authResponseHeader1)
234 | ->addAuthResponseHeaders($authResponseHeader2);
235 | }
236 |
237 | private function getMiddleware10Config(): HeadersConfig
238 | {
239 | $stsIncludeSubdomains = true;
240 | $addVaryHeader = true;
241 | $referrerPolicy = 'foobar';
242 | $accessControlAllowOrigin = 'foobar';
243 | $sslTemporaryRedirect = true;
244 | $contentTypeNosniff = true;
245 | $stsSeconds = 42;
246 | $sslRedirect = true;
247 | $accessControlAllowCredentials = true;
248 | $sslHost = 'foobar';
249 | $browserXssFilter = true;
250 | $contentSecurityPolicy = 'foobar';
251 | $sslForceHost = true;
252 | $forceSTSHeader = true;
253 | $publicKey = 'foobar';
254 | $frameDeny = true;
255 | $isDevelopment = true;
256 | $customBrowserXSSValue = 'foobar';
257 | $accessControlMaxAge = 42;
258 | $customFrameOptionsValue = 'foobar';
259 | $stsPreload = true;
260 | $featurePolicy = 'foobar';
261 |
262 | $accessControlAllowOriginList1 = 'foobar';
263 | $accessControlAllowOriginList2 = 'foobar';
264 | $accessControlAllowMethod1 = 'foobar';
265 | $accessControlAllowMethod2 = 'foobar';
266 | $hostsProxyHeader1 = 'foobar';
267 | $hostsProxyHeader2 = 'foobar';
268 | $accessControlAllowHeader1 = 'foobar';
269 | $accessControlAllowHeader2 = 'foobar';
270 | $allowedHost1 = 'foobar';
271 | $allowedHost2 = 'foobar';
272 | $accessControlExposeHeader1 = 'foobar';
273 | $accessControlExposeHeader2 = 'foobar';
274 |
275 | $customRequestHeader1Key = 'name0';
276 | $customRequestHeader1Value = 'foobar';
277 | $customRequestHeader2Key = 'name1';
278 | $customRequestHeader2Value = 'foobar';
279 |
280 | $sslProxyHeaders1Key = 'name0';
281 | $sslProxyHeaders1Value = 'foobar';
282 | $sslProxyHeaders2Key = 'name1';
283 | $sslProxyHeaders2Value = 'foobar';
284 |
285 | $customResponseHeader1Key = 'name0';
286 | $customResponseHeader1Value = 'foobar';
287 | $customResponseHeader2Key = 'name1';
288 | $customResponseHeader2Value = 'foobar';
289 |
290 | return (new HeadersConfig())
291 | ->addCustomRequestHeaders($customRequestHeader1Key, $customRequestHeader1Value)
292 | ->addCustomRequestHeaders($customRequestHeader2Key, $customRequestHeader2Value)
293 | ->addSslProxyHeaders($sslProxyHeaders1Key, $sslProxyHeaders1Value)
294 | ->addSslProxyHeaders($sslProxyHeaders2Key, $sslProxyHeaders2Value)
295 | ->addCustomResponseHeaders($customResponseHeader1Key, $customResponseHeader1Value)
296 | ->addCustomResponseHeaders($customResponseHeader2Key, $customResponseHeader2Value)
297 |
298 | ->addAccessControlAllowOriginList($accessControlAllowOriginList1)
299 | ->addAccessControlAllowOriginList($accessControlAllowOriginList2)
300 | ->addAccessControlAllowMethods($accessControlAllowMethod1)
301 | ->addAccessControlAllowMethods($accessControlAllowMethod2)
302 | ->addHostsProxyHeaders($hostsProxyHeader1)
303 | ->addHostsProxyHeaders($hostsProxyHeader2)
304 | ->addAccessControlAllowHeaders($accessControlAllowHeader1)
305 | ->addAccessControlAllowHeaders($accessControlAllowHeader2)
306 | ->addAllowedHosts($allowedHost1)
307 | ->addAllowedHosts($allowedHost2)
308 | ->addAccessControlExposeHeaders($accessControlExposeHeader1)
309 | ->addAccessControlExposeHeaders($accessControlExposeHeader2)
310 |
311 | ->setStsIncludeSubdomains($stsIncludeSubdomains)
312 | ->setAddVaryHeader($addVaryHeader)
313 | ->setAccessControlAllowOrigin($accessControlAllowOrigin)
314 | ->setSslTemporaryRedirect($sslTemporaryRedirect)
315 | ->setContentTypeNosniff($contentTypeNosniff)
316 | ->setStsSeconds($stsSeconds)
317 | ->setSslRedirect($sslRedirect)
318 | ->setAccessControlAllowCredentials($accessControlAllowCredentials)
319 | ->setSslHost($sslHost)
320 | ->setBrowserXssFilter($browserXssFilter)
321 | ->setContentSecurityPolicy($contentSecurityPolicy)
322 | ->setReferrerPolicy($referrerPolicy)
323 | ->setSslForceHost($sslForceHost)
324 | ->setForceSTSHeader($forceSTSHeader)
325 | ->setPublicKey($publicKey)
326 | ->setFrameDeny($frameDeny)
327 | ->setIsDevelopment($isDevelopment)
328 | ->setCustomBrowserXSSValue($customBrowserXSSValue)
329 | ->setAccessControlMaxAge($accessControlMaxAge)
330 | ->setCustomFrameOptionsValue($customFrameOptionsValue)
331 | ->setStsPreload($stsPreload)
332 | ->setFeaturePolicy($featurePolicy)
333 | ;
334 |
335 | }
336 |
337 | private function getMiddleware11Config(): IpWhiteListConfig
338 | {
339 | $ip1 = 'foobar';
340 | $ip2 = 'foobar';
341 | $ipStrategyDepth = 42;
342 |
343 | return (new IpWhiteListConfig())
344 | ->setIpStrategyDepth($ipStrategyDepth)
345 | ->addIpStrategyExcludedIP($ip1)
346 | ->addIpStrategyExcludedIP($ip2)
347 | ->addSourceRange($ip1)
348 | ->addSourceRange($ip2);
349 | }
350 |
351 | private function getMiddleware12Config(): InFlightReqConfig
352 | {
353 | $ip1 = 'foobar';
354 | $ip2 = 'foobar';
355 |
356 | $amount = 42;
357 | $ipStrategyDepth = 42;
358 | $requestHeaderName = 'foobar';
359 | $requestHost = true;
360 |
361 | $sourceCriterionConfig = (new SourceCriterion())
362 | ->setIpStrategyDepth($ipStrategyDepth)
363 | ->setRequestHeaderName($requestHeaderName)
364 | ->setRequestHost($requestHost)
365 | ->addIpStrategyExcludedIP($ip1)
366 | ->addIpStrategyExcludedIP($ip2);
367 |
368 | return (new InFlightReqConfig())
369 | ->setAmount($amount)
370 | ->setSourceCriterion($sourceCriterionConfig);
371 | }
372 |
373 | private function getMiddleware13Config(): PassTLSClientCertConfig
374 | {
375 | $subject = (new CertificateConfig())
376 | ->setCommonName(true)
377 | ->setCountry(true)
378 | ->setDomainComponent(true)
379 | ->setLocality(true)
380 | ->setOrganization(true)
381 | ->setProvince(true)
382 | ->setSerialNumber(true)
383 | ;
384 |
385 | $issuer = (new CertificateConfig())
386 | ->setCommonName(true)
387 | ->setCountry(true)
388 | ->setDomainComponent(true)
389 | ->setLocality(true)
390 | ->setOrganization(true)
391 | ->setProvince(true)
392 | ->setSerialNumber(true)
393 | ;
394 |
395 | return (new PassTLSClientCertConfig())
396 | ->setPem(true)
397 | ->setInfoNotAfter(true)
398 | ->setInfoNotBefore(true)
399 | ->setInfoSans(true)
400 | ->setInfoSerialNumber(true)
401 | ->setInfoSubject($subject)
402 | ->setInfoIssuer($issuer);
403 | }
404 |
405 | private function getMiddleware15Config(): RateLimitConfig
406 | {
407 | $ip1 = 'foobar';
408 | $ip2 = 'foobar';
409 | $average = 42;
410 | $period = '42';
411 | $burst = 42;
412 | $requestHeaderName = 'foobar';
413 | $requestHost = true;
414 | $ipStrategyDepth = 42;
415 |
416 | $sourceCriterionConfig = (new SourceCriterion())
417 | ->setRequestHeaderName($requestHeaderName)
418 | ->setRequestHost($requestHost)
419 | ->setIpStrategyDepth($ipStrategyDepth)
420 | ->addIpStrategyExcludedIP($ip1)
421 | ->addIpStrategyExcludedIP($ip2);
422 |
423 | return (new RateLimitConfig())
424 | ->setAverage($average)
425 | ->setPeriod($period)
426 | ->setBurst($burst)
427 | ->setSourceCriterion($sourceCriterionConfig);
428 | }
429 |
430 | private function getMiddleware16Config(): RedirectRegexConfig
431 | {
432 | $regex = 'foobar';
433 | $permanent = true;
434 | $replacement = 'foobar';
435 | return (new RedirectRegexConfig())
436 | ->setRegex($regex)
437 | ->setReplacement($replacement)
438 | ->setPermanent($permanent);
439 | }
440 |
441 | private function getMiddleware17Config(): RedirectSchemeConfig
442 | {
443 | $scheme = 'foobar';
444 | $permanent = true;
445 | $port = 'foobar';
446 | return (new RedirectSchemeConfig())
447 | ->setScheme($scheme)
448 | ->setPermanent($permanent)
449 | ->setPort($port);
450 | }
451 |
452 | private function getMiddleware18Config(): ReplacePathConfig
453 | {
454 | $path = 'foobar';
455 | return (new ReplacePathConfig())
456 | ->setPath($path);
457 | }
458 |
459 | private function getMiddleware19Config(): ReplacePathRegexConfig
460 | {
461 | $regex = 'foobar';
462 | $replacement = 'foobar';
463 | return (new ReplacePathRegexConfig())
464 | ->setRegex($regex)
465 | ->setReplacement($replacement);
466 | }
467 |
468 | private function getMiddleware20Config(): RetryConfig
469 | {
470 | return (new RetryConfig())
471 | ->setAttempts(42);
472 | }
473 |
474 | private function getMiddleware21Config(): StripPrefixConfig
475 | {
476 | return (new StripPrefixConfig())
477 | ->setForceSlash(true)
478 | ->addPrefixes('foobar')
479 | ->addPrefixes('foobar');
480 | }
481 |
482 | private function getMiddleware22Config(): StripPrefixRegexConfig
483 | {
484 | return ( new StripPrefixRegexConfig() )
485 | ->addRegex('foobar')
486 | ->addRegex('foobar');
487 | }
488 |
489 | protected function validateArray(array $source, array $target, string $message = '')
490 | {
491 |
492 | foreach ($source as $arrayKey => $arrayValue) {
493 | $currentMessage = implode(' -> ', [$message, $arrayKey]);
494 | if (!isset($target[$arrayKey])) {
495 | var_dump(array_keys($target));
496 | }
497 | $this->assertArrayHasKey($arrayKey, $target, $currentMessage);
498 |
499 | switch (gettype($arrayValue)) {
500 | case 'array':
501 | $this->validateArray($arrayValue, $target[$arrayKey], $currentMessage);
502 | break;
503 | case 'string':
504 | case 'integer':
505 | case 'boolean':
506 | case 'double':
507 | case 'float':
508 | $this->assertEquals($arrayValue, $target[$arrayKey], $currentMessage);
509 | break;
510 | default:
511 | var_dump([
512 | 'type' => gettype($arrayValue),
513 | 'source' => $source,
514 | 'target' => $target
515 | ]);
516 | $this->assertTrue(false);
517 | break;
518 | }
519 | }
520 | }
521 | }
522 |
--------------------------------------------------------------------------------
/tests/http/HttpMiddlewareTest.php:
--------------------------------------------------------------------------------
1 | setPrefix($prefixValue);
61 |
62 | $middleware = new AddPrefix($addPrefixConfig);
63 |
64 | $data = $middleware->getData();
65 |
66 | $this->assertEquals($name, $middleware->getName());
67 | $this->assertArrayHasKey('prefix', $data);
68 | $this->assertEquals($prefixValue, $data['prefix']);
69 | }
70 |
71 | public function testBasicAuth(): void {
72 | $name = 'basicAuth';
73 |
74 | $userTest = 'test:' . BasicAuthConfig::bcrypt('test');
75 |
76 | $usersFile = '/path/to/my/usersfile';
77 | $realm = 'traefik';
78 | $removeHeader = false;
79 | $headerField = 'X-WebAuth-User';
80 |
81 | $basicAuthConfig = (new BasicAuthConfig())
82 | ->setRemoveHeader($removeHeader)
83 | ->setUsersFile($usersFile)
84 | ->setRealm($realm)
85 | ->setHeaderField($headerField)
86 | ->addUser($userTest)
87 | ->addUserWithPassword('test2', 'test2');
88 |
89 | $middleware = new BasicAuth($basicAuthConfig);
90 |
91 | $data = $middleware->getData();
92 |
93 | $this->assertEquals($name, $middleware->getName());
94 |
95 | $this->assertEquals($usersFile, $data['usersFile'], 'usersFile');
96 | $this->assertEquals($realm, $data['realm'], 'realm');
97 | $this->assertEquals($removeHeader, $data['removeHeader'], 'removeHeader');
98 | $this->assertEquals($headerField, $data['headerField'], 'headerField');
99 |
100 | $this->assertArrayHasKey('users', $data);
101 | $this->assertContains($userTest, $data['users']);
102 | $this->assertEquals(0, strpos($data['users'][1], 'test2:'));
103 |
104 | }
105 |
106 | public function testBuffering(): void {
107 | $name = 'buffering';
108 |
109 | $maxRequestBodyBytes = 2000000;
110 | $memRequestBodyBytes = 2000000;
111 | $maxResponseBodyBytes = 2000000;
112 | $memResponseBodyBytes = 2000000;
113 | $retryExpression = 'IsNetworkError() && Attempts() < 2';
114 |
115 |
116 | $bufferingConfig = (new BufferingConfig())
117 | ->setMaxRequestBodyBytes($maxRequestBodyBytes)
118 | ->setMaxResponseBodyBytes($memRequestBodyBytes)
119 | ->setMemRequestBodyBytes($maxResponseBodyBytes)
120 | ->setMemResponseBodyBytes($memResponseBodyBytes)
121 | ->setRetryExpression($retryExpression);
122 | $middleware = new Buffering($bufferingConfig);
123 |
124 | $data = $middleware->getData();
125 |
126 | $this->assertEquals($name, $middleware->getName());
127 |
128 | $this->assertEquals($maxRequestBodyBytes, $data['maxRequestBodyBytes'], 'maxRequestBodyBytes');
129 | $this->assertEquals($memRequestBodyBytes, $data['memRequestBodyBytes'], 'memRequestBodyBytes');
130 | $this->assertEquals($maxResponseBodyBytes, $data['maxResponseBodyBytes'], 'maxResponseBodyBytes');
131 | $this->assertEquals($memResponseBodyBytes, $data['memResponseBodyBytes'], 'memResponseBodyBytes');
132 | $this->assertEquals($retryExpression, $data['retryExpression'], 'retryExpression');
133 | }
134 |
135 | public function testChain(): void {
136 | $name = 'chain';
137 | $chain1 = 'https-only';
138 | $chain2 = 'known-ips';
139 | $chain3 = 'auth-users';
140 |
141 | $chainConfig = (new ChainConfig())
142 | ->addMiddleware($chain1)
143 | ->addMiddleware($chain2)
144 | ->addMiddleware($chain3);
145 |
146 | $middleware = new Chain($chainConfig);
147 |
148 | $data = $middleware->getData();
149 |
150 | $this->assertEquals($name, $middleware->getName());
151 |
152 | $this->assertArrayHasKey('middlewares', $data);
153 | $this->assertContains($chain1, $data['middlewares']);
154 | $this->assertContains($chain2, $data['middlewares']);
155 | $this->assertContains($chain3, $data['middlewares']);
156 | }
157 |
158 | public function testCircuitbreaker(): void {
159 | $name = 'circuitBreaker';
160 | $expression = 'LatencyAtQuantileMS(50.0) > 100';
161 |
162 | $circuitBreakerConfig = (new CircuitBreakerConfig())
163 | ->setExpression($expression);
164 |
165 | $middleware = new CircuitBreaker($circuitBreakerConfig);
166 |
167 | $data = $middleware->getData();
168 |
169 | $this->assertEquals($name, $middleware->getName());
170 |
171 | $this->assertEquals($expression, $data['expression']);
172 | }
173 |
174 | public function testCompress(): void {
175 | $name = 'compress';
176 | $exclude1 = 'text/event-stream';
177 | $exclude2 = 'text/plain';
178 |
179 | $compressConfig = (new CompressConfig())
180 | ->addExcludedContentType($exclude1)
181 | ->addExcludedContentType($exclude2);
182 |
183 | $middleware = new Compress($compressConfig);
184 |
185 | $data = $middleware->getData();
186 |
187 | $this->assertEquals($name, $middleware->getName());
188 |
189 | $this->assertArrayHasKey('excludedContentTypes', $data);
190 | $this->assertContains($exclude1, $data['excludedContentTypes']);
191 | $this->assertContains($exclude2, $data['excludedContentTypes']);
192 | }
193 |
194 | public function testDigestauth(): void {
195 | $name = 'digestAuth';
196 | $realm = 'traefik';
197 | $user1 = 'test';
198 | $pass1 = 'test';
199 | $user2 = 'test2';
200 | $pass2 = 'test2';
201 |
202 | $userTest = $user1 . ':' . $pass1 . ':' . DigestauthConfig::htdigest($user1, $realm, $pass1);
203 |
204 | $usersFile = '/path/to/my/usersfile';
205 | $removeHeader = false;
206 | $headerField = 'X-WebAuth-User';
207 |
208 | $digestAuthConfig = (new DigestAuthConfig())
209 | ->setHeaderField($headerField)
210 | ->setRealm($realm)
211 | ->setRemoveHeader($removeHeader)
212 | ->setUsersFile($usersFile)
213 | ->addUser($userTest);
214 |
215 | $digestAuthConfig->addUserWithPassword($user2, $pass2);
216 |
217 | $middleware = new DigestAuth($digestAuthConfig);
218 |
219 | $data = $middleware->getData();
220 |
221 | $this->assertEquals($name, $middleware->getName());
222 |
223 | $this->assertEquals($usersFile, $data['usersFile'], 'usersFile');
224 | $this->assertEquals($realm, $data['realm'], 'realm');
225 | $this->assertEquals($removeHeader, $data['removeHeader'], 'removeHeader');
226 | $this->assertEquals($headerField, $data['headerField'], 'headerField');
227 |
228 | $this->assertArrayHasKey('users', $data);
229 | $this->assertContains($userTest, $data['users']);
230 | $this->assertEquals(0, strpos($data['users'][1], $user2 . ':'));
231 | }
232 |
233 | public function testErrorpage(): void {
234 | $name = 'errors';
235 |
236 | $errorRange = '500-599';
237 |
238 | $service = 'serviceError';
239 | $query = '/{status}.html';
240 |
241 | $errorPageConfig = (new ErrorPageConfig())
242 | ->setQuery($query)
243 | ->setService($service)
244 | ->addStatus($errorRange);
245 |
246 | $middleware = new ErrorPage($errorPageConfig);
247 |
248 | $data = $middleware->getData();
249 |
250 | $this->assertEquals($name, $middleware->getName());
251 |
252 | $this->assertEquals($service, $data['service'], 'service');
253 | $this->assertEquals($query, $data['query'], 'query');
254 |
255 | $this->assertArrayHasKey('status', $data);
256 | $this->assertContains($errorRange, $data['status']);
257 | }
258 |
259 | public function testForwardauth(): void {
260 | $name = 'forwardAuth';
261 |
262 | $address = 'https://example.com/auth';
263 | $trustForwardHeader = true;
264 | $authResponseHeader1 = 'X-Auth-User';
265 | $authResponseHeader2 = 'X-Secret';
266 |
267 | $ca = "path/to/local.crt";
268 | $caOptional = true;
269 | $cert = "path/to/foo.cert";
270 | $key = "path/to/foo.key";
271 | $insecureSkipVerify = true;
272 |
273 | $tlsConfig = (new TlsConfig())
274 | ->setInsecureSkipVerify($insecureSkipVerify)
275 | ->setKey($key)
276 | ->setCert($cert)
277 | ->setCaOptional($caOptional)
278 | ->setCa($ca);
279 |
280 | $forwardAuthConfig = (new ForwardAuthConfig())
281 | ->setTrustForwardHeader($trustForwardHeader)
282 | ->setTls($tlsConfig)
283 | ->setAddress($address)
284 | ->addAuthResponseHeaders($authResponseHeader1)
285 | ->addAuthResponseHeaders($authResponseHeader2);
286 |
287 | $middleware = new ForwardAuth($forwardAuthConfig);
288 |
289 | $data = $middleware->getData();
290 |
291 | $this->assertEquals($name, $middleware->getName());
292 |
293 | $this->assertEquals($address, $data['address'], 'address');
294 | $this->assertEquals($trustForwardHeader, $data['trustForwardHeader'], 'trustForwardHeader');
295 |
296 | $this->assertArrayHasKey('tls', $data);
297 | $this->assertEquals($ca, $data['tls']['ca'], 'tls.ca');
298 | $this->assertEquals($caOptional, $data['tls']['caOptional'], 'tls.caOptional');
299 | $this->assertEquals($cert, $data['tls']['cert'], 'tls.cert');
300 | $this->assertEquals($key, $data['tls']['key'], 'tls.key');
301 | $this->assertEquals($insecureSkipVerify, $data['tls']['insecureSkipVerify'], 'tls.insecureSkipVerify');
302 |
303 | $this->assertArrayHasKey('authResponseHeaders', $data);
304 | $this->assertContains($authResponseHeader1, $data['authResponseHeaders']);
305 | $this->assertContains($authResponseHeader2, $data['authResponseHeaders']);
306 | }
307 |
308 | public function testHeaders(): void {
309 | $name = 'headers';
310 |
311 | $frameDeny = true;
312 | $sslRedirect = true;
313 |
314 | $customRequestHeaders1Key = 'X-Script-Name';
315 | $customRequestHeaders1Value = 'test';
316 | $customRequestHeaders2Key = 'X-Custom-Request-Header';
317 | $customRequestHeaders2Value = '';
318 |
319 | $customResponseHeaders1Key = 'X-Custom-Response-Header';
320 | $customResponseHeaders1Value = '';
321 |
322 | $headersConfig = (new HeadersConfig())
323 | ->setFrameDeny($frameDeny)
324 | ->setSslRedirect($sslRedirect)
325 | ->addCustomRequestHeaders($customRequestHeaders1Key, $customRequestHeaders1Value)
326 | ->addCustomRequestHeaders($customRequestHeaders2Key, $customRequestHeaders2Value)
327 | ->addCustomResponseHeaders($customResponseHeaders1Key, $customResponseHeaders1Value);
328 |
329 | $middleware = new Headers($headersConfig);
330 |
331 | $data = $middleware->getData();
332 |
333 | $this->assertEquals($name, $middleware->getName());
334 |
335 | $this->assertEquals($frameDeny, $data['frameDeny'], 'frameDeny');
336 | $this->assertEquals($sslRedirect, $data['sslRedirect'], 'sslRedirect');
337 |
338 | $this->assertArrayHasKey('customRequestHeaders', $data);
339 | $this->assertArrayHasKey('customResponseHeaders', $data);
340 | }
341 |
342 | public function testIpwhitelist(): void {
343 | $name = 'ipWhiteList';
344 | $ip1 = '127.0.0.1/32';
345 | $ip2 = '192.168.1.7';
346 | $ipStrategyDepth = 2;
347 |
348 | $sourceCriterionConfig = (new IpWhiteListConfig())
349 | ->setIpStrategyDepth($ipStrategyDepth)
350 | ->addIpStrategyExcludedIP($ip1)
351 | ->addIpStrategyExcludedIP($ip2)
352 | ->addSourceRange($ip1)
353 | ->addSourceRange($ip2);
354 |
355 | $middleware = new IpWhiteList($sourceCriterionConfig);
356 |
357 | $data = $middleware->getData();
358 |
359 | $this->assertEquals($name, $middleware->getName());
360 |
361 | $this->assertArrayHasKey('sourceRange', $data);
362 | $this->assertContains($ip1, $data['sourceRange']);
363 | $this->assertContains($ip2, $data['sourceRange']);
364 |
365 | $this->assertArrayHasKey('ipStrategy', $data);
366 | $this->assertArrayHasKey('depth', $data['ipStrategy']);
367 | $this->assertArrayHasKey('excludedIPs', $data['ipStrategy']);
368 |
369 | $this->assertEquals($ipStrategyDepth, $data['ipStrategy']['depth'], 'ipStrategy.depth');
370 |
371 | $this->assertContains($ip1, $data['ipStrategy']['excludedIPs']);
372 | $this->assertContains($ip2, $data['ipStrategy']['excludedIPs']);
373 | }
374 |
375 | public function testInflightreq(): void {
376 | $name = 'inFlightReq';
377 | $ip1 = '127.0.0.1/32';
378 | $ip2 = '192.168.1.7';
379 |
380 | $amount = 10;
381 | $ipStrategyDepth = 2;
382 | $requestHeaderName = 'username';
383 | $requestHost = true;
384 |
385 | $sourceCriterionConfig = (new SourceCriterion())
386 | ->setIpStrategyDepth($ipStrategyDepth)
387 | ->setRequestHeaderName($requestHeaderName)
388 | ->setRequestHost($requestHost)
389 | ->addIpStrategyExcludedIP($ip1)
390 | ->addIpStrategyExcludedIP($ip2);
391 |
392 | $inFlightReqConfig = (new InFlightReqConfig())
393 | ->setAmount($amount)
394 | ->setSourceCriterion($sourceCriterionConfig);
395 |
396 | $middleware = new InFlightReq($inFlightReqConfig);
397 |
398 | $data = $middleware->getData();
399 |
400 | $this->assertEquals($name, $middleware->getName());
401 |
402 | $this->assertEquals($amount, $data['amount'], 'amount');
403 |
404 | $this->assertArrayHasKey('sourceCriterion', $data);
405 |
406 | $this->assertEquals(
407 | $requestHeaderName,
408 | $data['sourceCriterion']['requestHeaderName'],
409 | 'sourceCriterion.requestHeaderName'
410 | );
411 |
412 | $this->assertEquals(
413 | $requestHost,
414 | $data['sourceCriterion']['requestHost'],
415 | 'sourceCriterion.requestHost'
416 | );
417 |
418 | $this->assertArrayHasKey('ipStrategy', $data['sourceCriterion']);
419 |
420 | $this->assertArrayHasKey('depth', $data['sourceCriterion']['ipStrategy']);
421 | $this->assertArrayHasKey('excludedIPs', $data['sourceCriterion']['ipStrategy']);
422 |
423 | $this->assertEquals(
424 | $ipStrategyDepth,
425 | $data['sourceCriterion']['ipStrategy']['depth'],
426 | 'ipStrategy.depth'
427 | );
428 |
429 | $this->assertContains(
430 | $ip1,
431 | $data['sourceCriterion']['ipStrategy']['excludedIPs']
432 | );
433 | $this->assertContains(
434 | $ip2,
435 | $data['sourceCriterion']['ipStrategy']['excludedIPs']
436 | );
437 | }
438 |
439 | public function testPasstlsclientcert(): void {
440 | $name = 'passTLSClientCert';
441 | $expectedOptions = [
442 | 'pem' => true,
443 | 'info' => [
444 | 'notAfter' => true,
445 | 'notBefore' => true,
446 | 'sans' => true,
447 | 'subject' => [
448 | 'country' => true,
449 | 'province' => true,
450 | 'locality' => true,
451 | 'organization' => true,
452 | 'commonName' => true,
453 | 'serialNumber' => true,
454 | 'domainComponent' => true
455 | ],
456 | 'issuer' => [
457 | 'country' => true,
458 | 'province' => true,
459 | 'locality' => true,
460 | 'organization' => true,
461 | 'commonName' => true,
462 | 'serialNumber' => true,
463 | 'domainComponent' => true
464 | ],
465 | ]
466 |
467 | ];
468 | $subject = (new CertificateConfig())
469 | ->setCommonName(true)
470 | ->setCountry(true)
471 | ->setDomainComponent(true)
472 | ->setLocality(true)
473 | ->setOrganization(true)
474 | ->setProvince(true)
475 | ->setSerialNumber(true);
476 |
477 | $issuer = (new CertificateConfig())
478 | ->setCommonName(true)
479 | ->setCountry(true)
480 | ->setDomainComponent(true)
481 | ->setLocality(true)
482 | ->setOrganization(true)
483 | ->setProvince(true)
484 | ->setSerialNumber(true);
485 |
486 | $passTLSClientCertConfig = (new PassTLSClientCertConfig())
487 | ->setPem(true)
488 | ->setInfoNotAfter(true)
489 | ->setInfoNotBefore(true)
490 | ->setInfoSans(true)
491 | ->setInfoSubject($subject)
492 | ->setInfoIssuer($issuer);
493 | $middleware = new PassTLSClientCert($passTLSClientCertConfig);
494 |
495 | $data = $middleware->getData();
496 |
497 | $this->assertEquals($name, $middleware->getName());
498 | $this->assertTrue($expectedOptions == $data);
499 | }
500 |
501 | public function testRatelimit(): void {
502 | $name = 'rateLimit';
503 | $ip1 = '127.0.0.1/32';
504 | $ip2 = '192.168.1.7';
505 | $average = 100;
506 | $period = '1m';
507 | $burst = 50;
508 | $requestHeaderName = 'username';
509 | $requestHost = true;
510 | $ipStrategyDepth = 2;
511 |
512 | $sourceCriterionConfig = (new SourceCriterion())
513 | ->setRequestHeaderName($requestHeaderName)
514 | ->setRequestHost($requestHost)
515 | ->setIpStrategyDepth($ipStrategyDepth)
516 | ->addIpStrategyExcludedIP($ip1)
517 | ->addIpStrategyExcludedIP($ip2);
518 |
519 | $rateLimitConfig = (new RatelimitConfig())
520 | ->setAverage($average)
521 | ->setPeriod($period)
522 | ->setBurst($burst)
523 | ->setSourceCriterion($sourceCriterionConfig);
524 |
525 | $middleware = new RateLimit($rateLimitConfig);
526 |
527 | $data = $middleware->getData();
528 |
529 | $this->assertEquals($name, $middleware->getName());
530 |
531 | $this->assertArrayHasKey('average', $data);
532 | $this->assertEquals($average, $data['average']);
533 | $this->assertArrayHasKey('period', $data);
534 | $this->assertEquals($period, $data['period']);
535 | $this->assertArrayHasKey('burst', $data);
536 | $this->assertEquals($burst, $data['burst']);
537 |
538 | $this->assertArrayHasKey('sourceCriterion', $data);
539 |
540 | $this->assertEquals(
541 | $requestHeaderName,
542 | $data['sourceCriterion']['requestHeaderName'],
543 | 'sourceCriterion.requestHeaderName'
544 | );
545 |
546 | $this->assertEquals(
547 | $requestHost,
548 | $data['sourceCriterion']['requestHost'],
549 | 'sourceCriterion.requestHost'
550 | );
551 |
552 | $this->assertArrayHasKey('ipStrategy', $data['sourceCriterion']);
553 |
554 | $this->assertArrayHasKey('depth', $data['sourceCriterion']['ipStrategy']);
555 | $this->assertArrayHasKey('excludedIPs', $data['sourceCriterion']['ipStrategy']);
556 |
557 | $this->assertEquals(
558 | $ipStrategyDepth,
559 | $data['sourceCriterion']['ipStrategy']['depth'],
560 | 'ipStrategy.depth'
561 | );
562 |
563 | $this->assertContains(
564 | $ip1,
565 | $data['sourceCriterion']['ipStrategy']['excludedIPs']
566 | );
567 | $this->assertContains(
568 | $ip2,
569 | $data['sourceCriterion']['ipStrategy']['excludedIPs']
570 | );
571 | }
572 |
573 | public function testRedirectscheme(): void {
574 | $name = 'redirectScheme';
575 |
576 | $scheme = 'https';
577 | $port = '443';
578 | $permanent = true;
579 |
580 | $redirectSchemeConfig = (new RedirectSchemeConfig())
581 | ->setScheme('https')
582 | ->setPort('443')
583 | ->setPermanent(true);
584 |
585 | $middleware = new RedirectScheme($redirectSchemeConfig);
586 |
587 | $data = $middleware->getData();
588 |
589 | $this->assertEquals($name, $middleware->getName());
590 | $this->assertArrayHasKey('scheme', $data);
591 | $this->assertEquals($scheme, $data['scheme']);
592 |
593 | $this->assertArrayHasKey('port', $data);
594 | $this->assertEquals($port, $data['port']);
595 |
596 | $this->assertArrayHasKey('permanent', $data);
597 | $this->assertEquals($permanent, $data['permanent']);
598 | }
599 |
600 | public function testRedirectregex(): void {
601 | $name = 'redirectRegex';
602 |
603 | $regex = '^http://localhost/(.*)';
604 | $replacement = 'http://mydomain/${1}';
605 | $permanent = true;
606 |
607 | $redirectRegexConfig = (new RedirectRegexConfig())
608 | ->setRegex($regex)
609 | ->setReplacement($replacement)
610 | ->setPermanent($permanent);
611 |
612 | $middleware = new RedirectRegex($redirectRegexConfig);
613 |
614 | $data = $middleware->getData();
615 |
616 | $this->assertEquals($name, $middleware->getName());
617 | $this->assertArrayHasKey('regex', $data);
618 | $this->assertEquals($regex, $data['regex']);
619 |
620 | $this->assertArrayHasKey('replacement', $data);
621 | $this->assertEquals($replacement, $data['replacement']);
622 |
623 | $this->assertArrayHasKey('permanent', $data);
624 | $this->assertEquals($permanent, $data['permanent']);
625 | }
626 |
627 | public function testReplacepath(): void {
628 | $name = 'replacePath';
629 |
630 | $path = '/foo';
631 |
632 | $replacePathConfig = (new ReplacePathConfig())
633 | ->setPath($path);
634 |
635 | $middleware = new ReplacePath($replacePathConfig);
636 |
637 | $data = $middleware->getData();
638 |
639 | $this->assertEquals($name, $middleware->getName());
640 | $this->assertArrayHasKey('path', $data);
641 | $this->assertEquals($path, $data['path']);
642 | }
643 |
644 | public function testReplacepathregex(): void {
645 |
646 | $name = 'replacePathRegex';
647 |
648 | $regex = '^/foo/(.*)';
649 | $replacement = '/bar/$1';
650 |
651 | $replacePathRegexConfig = (new ReplacePathRegexConfig())
652 | ->setRegex($regex)
653 | ->setReplacement($replacement);
654 |
655 | $middleware = new ReplacePathRegex($replacePathRegexConfig);
656 |
657 | $data = $middleware->getData();
658 |
659 | $this->assertEquals($name, $middleware->getName());
660 |
661 | $this->assertArrayHasKey('regex', $data);
662 | $this->assertEquals($regex, $data['regex']);
663 |
664 | $this->assertArrayHasKey('replacement', $data);
665 | $this->assertEquals($replacement, $data['replacement']);
666 | }
667 |
668 | public function testRetry(): void {
669 | $name = 'retry';
670 | $attempts = 50;
671 |
672 | $retryConfig = (new RetryConfig())
673 | ->setAttempts($attempts);
674 |
675 | $middleware = new Retry($retryConfig);
676 |
677 | $data = $middleware->getData();
678 |
679 | $this->assertEquals($name, $middleware->getName());
680 | $this->assertArrayHasKey('attempts', $data);
681 | $this->assertEquals($attempts, $data['attempts']);
682 | }
683 |
684 | public function testStripprefix(): void {
685 | $name = 'stripPrefix';
686 | $prefix1 = '/foobar';
687 | $prefix2 = '/foobar';
688 |
689 | $forceSlash = false;
690 |
691 | $stripPrefixConfig = (new StripPrefixConfig())
692 | ->setForceSlash($forceSlash)
693 | ->addPrefixes($prefix1)
694 | ->addPrefixes($prefix2);
695 |
696 | $middleware = new StripPrefix($stripPrefixConfig);
697 |
698 | $data = $middleware->getData();
699 |
700 | $this->assertEquals($name, $middleware->getName());
701 | $this->assertArrayHasKey('forceSlash', $data);
702 | $this->assertEquals($forceSlash, $data['forceSlash']);
703 |
704 | $this->assertArrayHasKey('prefixes', $data);
705 | $this->assertContains($prefix1, $data['prefixes']);
706 | $this->assertContains($prefix2, $data['prefixes']);
707 | }
708 |
709 | public function testStripprefixregex(): void {
710 |
711 | $name = 'stripPrefixRegex';
712 | $prefixRegex1 = '/foo/[a-z0-9]+/[0-9]+/';
713 |
714 | $stripPrefixRegexConfig = (new StripPrefixRegexConfig())
715 | ->addRegex($prefixRegex1);
716 |
717 | $middleware = new StripPrefixRegex($stripPrefixRegexConfig);
718 |
719 | $data = $middleware->getData();
720 |
721 | $this->assertEquals($name, $middleware->getName());
722 |
723 | $this->assertArrayHasKey('regex', $data);
724 | $this->assertContains($prefixRegex1, $data['regex']);
725 | }
726 | }
727 |
--------------------------------------------------------------------------------