From 13cd23a6418929c03598cf199da47eda0f92ebca Mon Sep 17 00:00:00 2001 From: codenoid <14269809+codenoid@users.noreply.github.com> Date: Tue, 20 Aug 2024 09:44:32 +0700 Subject: [PATCH] implement auth and header set option --- src/LokalSo/Lokal.php | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/LokalSo/Lokal.php b/src/LokalSo/Lokal.php index 2c77265..95fb455 100644 --- a/src/LokalSo/Lokal.php +++ b/src/LokalSo/Lokal.php @@ -59,6 +59,74 @@ class Options implements JsonSerializable public function __construct() {} + public function setBasicAuth(string $username, string $password): self + { + $auth = "{$username}:{$password}"; + if (!in_array($auth, $this->basic_auth)) { + $this->basic_auth[] = $auth; + } + return $this; + } + + public function setCIDRAllow(string $cidr): self + { + if (!in_array($cidr, $this->cidr_allow)) { + $this->cidr_allow[] = $cidr; + } + return $this; + } + + public function setCIDRDeny(string $cidr): self + { + if (!in_array($cidr, $this->cidr_deny)) { + $this->cidr_deny[] = $cidr; + } + return $this; + } + + public function addRequestHeader(string $key, string $value): self + { + $header = "{$key}:{$value}"; + if (!in_array($header, $this->request_header_add)) { + $this->request_header_add[] = $header; + } + return $this; + } + + public function removeRequestHeader(string $header): self + { + if (!in_array($header, $this->request_header_remove)) { + $this->request_header_remove[] = $header; + } + return $this; + } + + public function addResponseHeader(string $key, string $value): self + { + $header = "{$key}:{$value}"; + if (!in_array($header, $this->response_header_add)) { + $this->response_header_add[] = $header; + } + return $this; + } + + public function removeResponseHeader(string $header): self + { + if (!in_array($header, $this->response_header_remove)) { + $this->response_header_remove[] = $header; + } + return $this; + } + + public function setHeaderKey(string $key, string $value): self + { + $header = "{$key}:{$value}"; + if (!in_array($header, $this->header_key)) { + $this->header_key[] = $header; + } + return $this; + } + public function jsonSerialize(): array { return get_object_vars($this); @@ -153,6 +221,12 @@ public function setLocalAddress(string $local_address): Tunnel return $this; } + public function setOptions(Options $options): Tunnel + { + $this->options = $options; + return $this; + } + public function setTunnelType(string $tunnel_type): Tunnel { $this->tunnel_type = $tunnel_type;