Skip to content

Commit c8cd9a5

Browse files
authored
Merge pull request #14 from utopia-php/feat-header-management
Add removeHeader and clearHeaders methods to Client
2 parents 0a7271a + 67bbc09 commit c8cd9a5

4 files changed

Lines changed: 40 additions & 15 deletions

File tree

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"type": "library",
55
"license": "MIT",
66
"require": {
7-
"php": ">=8.0"
7+
"php": ">=8.1"
88
},
99
"require-dev": {
10+
"phpstan/phpstan": "^1.10",
1011
"phpunit/phpunit": "^9.5",
11-
"laravel/pint": "^1.5.0",
12-
"phpstan/phpstan": "^1.10"
12+
"laravel/pint": "^1.5.0"
1313
},
1414
"scripts": {
1515
"lint": "./vendor/bin/pint --test --config pint.json",

src/Client.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ public function addHeader(string $key, string $value): self
4848
return $this;
4949
}
5050

51+
/**
52+
* Remove a specific header.
53+
*
54+
* @param string $key
55+
* @return self
56+
*/
57+
public function removeHeader(string $key): self
58+
{
59+
unset($this->headers[strtolower($key)]);
60+
return $this;
61+
}
62+
63+
/**
64+
* Clear all headers.
65+
*
66+
* @return self
67+
*/
68+
public function clearHeaders(): self
69+
{
70+
$this->headers = [];
71+
return $this;
72+
}
73+
5174
/**
5275
* Set the request timeout.
5376
*

src/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct($message)
1212
{
1313
parent::__construct($message); // Call the parent constructor
1414
}
15-
public function __toString()
15+
public function __toString(): string
1616
{
1717
return __CLASS__ . " {$this->message}\n"; // Return the class name, code and message
1818
}

src/Response.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
$this->headers = $headers;
4747
$this->statusCode = $statusCode;
4848
}
49-
# Getters
49+
5050
/**
5151
* This method is used to get the response body as string
5252
* @return mixed
@@ -55,6 +55,7 @@ public function getBody(): mixed
5555
{
5656
return $this->body;
5757
}
58+
5859
/**
5960
* This method is used to get the response headers
6061
* @return array<string, string>
@@ -63,6 +64,7 @@ public function getHeaders(): array
6364
{
6465
return $this->headers;
6566
}
67+
6668
/**
6769
* This method is used to get the response status code
6870
* @return int
@@ -71,19 +73,19 @@ public function getStatusCode(): int
7173
{
7274
return $this->statusCode;
7375
}
74-
// Methods
7576

7677
/**
77-
* This method is used to convert the response body to text
78-
* @return string
79-
*/
78+
* This method is used to convert the response body to text
79+
* @return string
80+
*/
8081
public function text(): string
8182
{
8283
return \strval($this->body);
8384
}
85+
8486
/**
85-
* This method is used to convert the response body to JSON
86-
* @return mixed
87+
* This method is used to convert the response body to JSON
88+
* @return mixed
8789
*/
8890
public function json(): mixed
8991
{
@@ -94,10 +96,10 @@ public function json(): mixed
9496
return $data;
9597
}
9698

97-
/*
98-
* This method is used to convert the response body to blob
99-
* @return string
100-
*/
99+
/**
100+
* This method is used to convert the response body to blob
101+
* @return string
102+
*/
101103
public function blob(): string
102104
{
103105
$bin = "";

0 commit comments

Comments
 (0)