Skip to content

Commit 0b0d37e

Browse files
A few issue fixes
Response headers were still being sent even after the Response->respond() method was called. Problem: It was causing an error if using echo in the user code. Solution: Updated Response->respond() method to exit after the response is sent causing the execution to end immidieately for a given request. Some servers are not supporting HTTP Methods except for GET and POST Problem: Need a way to send PUT, PATCH and DELETE as they are commonly used Http Methods Solution: Supported a header X-HTTP-METHOD-OVERRIDE whose value can be the HTTP method you need to send. This can be achieved using http POST request too.# On branch master
1 parent eac9deb commit 0b0d37e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/request/Request.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ private function __construct(){
1414
$this->params = $_GET;
1515
$this->headers = array_change_key_case(getallheaders(),CASE_UPPER);
1616
$this->cookies = $_COOKIE;
17+
if(isset($this->headers['X-HTTP-METHOD-OVERRIDE'])){
18+
$this->method = $this->headers['X-HTTP-METHOD-OVERRIDE'];
19+
}
1720
}
1821

1922
private static $request;

src/response/Response.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ public function __construct(?string $data, $status=200){
1818
public function respond() : void{
1919
http_response_code($this->status);
2020
echo $this->data;
21+
exit;
2122
}
2223
}

0 commit comments

Comments
 (0)