Skip to content

Commit c01f37a

Browse files
committed
Ensure types safety and return an empty string when the header field doesn't exist
1 parent a42253c commit c01f37a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/WaterPipe/HTTP/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function setField(string $name, string $value)
5151

5252
public function getField(string $name): string
5353
{
54-
return $this->_fields[$name];
54+
return array_key_exists($name, $this->_fields) ? $this->_fields[$name] : "";
5555
}
5656

5757
public function toArray(): array

src/WaterPipe/HTTP/Request/RequestHeader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ public function getConnection(): string
138138

139139
public function setContentLength(int $value)
140140
{
141-
$this->setField("Content-Length", $value);
141+
$this->setField("Content-Length", strval($value));
142142
}
143143

144144
public function getContentLength(): int
145145
{
146-
return $this->getField("Content-Length");
146+
return intval($this->getField("Content-Length"));
147147
}
148148

149149
public function setContentType(string $value)
@@ -258,12 +258,12 @@ public function getIfUnmodifiedSince(): string
258258

259259
public function setMaxForward(int $value)
260260
{
261-
$this->setField("Max-Forward", $value);
261+
$this->setField("Max-Forward", strval($value));
262262
}
263263

264264
public function getMaxForward(): int
265265
{
266-
return $this->getField("Max-Forward");
266+
return intval($this->getField("Max-Forward"));
267267
}
268268

269269
public function setOrigin(string $value)

src/WaterPipe/HTTP/Response/ResponseHeader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ public function getAcceptRanges(): string
6868

6969
public function setAge(int $value)
7070
{
71-
$this->setField("Age", $value);
71+
$this->setField("Age", strval($value));
7272
}
7373

7474
public function getAge(): int
7575
{
76-
return $this->getField("Age");
76+
return intval($this->getField("Age"));
7777
}
7878

7979
public function setAllow(string $value)
@@ -148,12 +148,12 @@ public function getContentLanguage(): string
148148

149149
public function setContentLength(int $value)
150150
{
151-
$this->setField("Content-Length", $value);
151+
$this->setField("Content-Length", strval($value));
152152
}
153153

154154
public function getContentLength(): int
155155
{
156-
return $this->getField("Content-Length");
156+
return intval($this->getField("Content-Length"));
157157
}
158158

159159
public function setContentLocation(string $value)

0 commit comments

Comments
 (0)