Skip to content

Commit 9ff8c3b

Browse files
committed
Separate send method
1 parent e993300 commit 9ff8c3b

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/WaterPipe/HTTP/Response/Response.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ public function send()
7373
// Execute middleware
7474
WaterPipe::triggerBeforeSendEvent($this);
7575

76+
// Send headers
77+
$this->sendHeaders();
78+
79+
// Send body
80+
$this->sendBody();
81+
82+
// Exit properly
83+
$this->close();
84+
}
85+
86+
public function sendHeaders() : self
87+
{
7688
// Set status code
7789
$code = $this->_status->getCode();
7890
$text = $this->_status->getDescription();
@@ -93,11 +105,15 @@ public function send()
93105
}
94106
}
95107

96-
// Send body
108+
return $this;
109+
}
110+
111+
public function sendBody() : self
112+
{
113+
// Print the body
97114
echo $this->_body;
98115

99-
// Exit properly
100-
exit(0);
116+
return $this;
101117
}
102118

103119
/**
@@ -200,6 +216,11 @@ public function sendFile(string $path, int $status = 200, string $mime = null)
200216
}
201217
}
202218

219+
public function close()
220+
{
221+
exit(0);
222+
}
223+
203224
/**
204225
* Redirect the current request to another URI
205226
*
@@ -212,7 +233,7 @@ public function redirect(string $uri)
212233
$this->_status = new ResponseStatus(ResponseStatus::PermanentRedirectCode);
213234
$this->_header->setLocation($uri);
214235

215-
$this->send();
236+
$this->sendHeaders()->close();
216237
}
217238

218239
/**

0 commit comments

Comments
 (0)