Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/WebFiori/http into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Nov 27, 2024
2 parents 842d9ae + 00f368c commit 38f4aa9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/php83.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,10 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
release_staging:
needs:
- "test"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
- uses: google-github-actions/release-please-action@v3
with:
release-type: php
token: ${{ secrets.GITHUB_TOKEN }}


release_prod:
name: Publish Release
needs:
- "test"
runs-on: ubuntu-latest
Expand All @@ -63,4 +55,5 @@ jobs:
- uses: google-github-actions/release-please-action@v3
with:
release-type: php
config-file: release-please-config.json
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"PSR-7",
"JSONx"
],
"version":"3.3.15",
"license": "MIT",
"require": {
"php": ">=7.0",
Expand Down
26 changes: 26 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"include-v-in-tag":true,
"tag-separator": "-",
"packages":{
".":{
"changelog-path": "CHANGELOG.md",
"changelog-sections": [
{ "type": "feat", "section": "Features" },
{ "type": "feature", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "perf", "section": "Performance Improvements" },
{ "type": "revert", "section": "Reverts" },
{ "type": "docs", "section": "Documentation" },
{ "type": "style", "section": "Styles" },
{ "type": "chore", "section": "Miscellaneous Chores" },
{ "type": "refactor", "section": "Code Refactoring" },
{ "type": "test", "section": "Testing" },
{ "type": "build", "section": "Build System" },
{ "type": "ci", "section": "Continuous Integration" },
{ "type": "ui", "section": "User Interface" },
{ "type": "database", "section": "Database Changes" },
{ "type": "email", "section": "Email Notifications Changes" }
]
}
}
}
52 changes: 40 additions & 12 deletions webfiori/http/APITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ public function addFile(string $fileIdx, string $filePath, bool $reset = false)
* @param array $parameters A dictionary thar represents the parameters that
* will be sent to the endpoint. The name is parameter name as it appears in
* service implementation and its value is the value of the parameter.
*
* @param array $httpHeaders An optional associative array that can be used
* to mimic HTTP request headers. The keys of the array are names of headers
* and the value of each key represents the value of the header.
*
* @return string The method will return the output of the endpoint.
*/
public function callEndpoint(WebServicesManager $manager, string $requestMethod, string $apiEndpointName, array $parameters = []) : string {
public function callEndpoint(WebServicesManager $manager, string $requestMethod, string $apiEndpointName, array $parameters = [], array $httpHeaders = []) : string {
$manager->setOutputStream(fopen(self::OUTPUT_STREAM,'w'));
$method = strtoupper($requestMethod);
putenv('REQUEST_METHOD='.$method);
Expand All @@ -90,13 +94,13 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
}
$_POST['service'] = $apiEndpointName;
$_SERVER['CONTENT_TYPE'] = 'multipart/form-data';
$this->unset($_POST, $parameters, $manager);
$this->unset($_POST, $parameters, $manager, $httpHeaders);
} else {
foreach ($parameters as $key => $val) {
$_GET[$key] = $this->parseVal($val);
}
$_GET['service'] = $apiEndpointName;
$this->unset($_GET, $parameters, $manager);
$this->unset($_GET, $parameters, $manager, $httpHeaders);
}

$retVal = $manager->readOutputStream();
Expand Down Expand Up @@ -141,11 +145,15 @@ private function parseVal($val) {
* @param array $parameters An optional array of request parameters that can be
* passed to the endpoint.
*
* @param array $httpHeaders An optional associative array that can be used
* to mimic HTTP request headers. The keys of the array are names of headers
* and the value of each key represents the value of the header.
*
* @return string The method will return the output that was produced by
* the endpoint as string.
*/
public function deletRequest(WebServicesManager $manager, string $endpoint, array $parameters = []) : string {
return $this->callEndpoint($manager, RequestMethod::DELETE, $endpoint, $parameters);
public function deletRequest(WebServicesManager $manager, string $endpoint, array $parameters = [], array $httpHeaders = []) : string {
return $this->callEndpoint($manager, RequestMethod::DELETE, $endpoint, $parameters, $httpHeaders);
}
/**
* Sends a GET request to specific endpoint.
Expand All @@ -160,8 +168,8 @@ public function deletRequest(WebServicesManager $manager, string $endpoint, arra
* @return string The method will return the output that was produced by
* the endpoint as string.
*/
public function getRequest(WebServicesManager $manager, string $endpoint, array $parameters = []) : string {
return $this->callEndpoint($manager, RequestMethod::GET, $endpoint, $parameters);
public function getRequest(WebServicesManager $manager, string $endpoint, array $parameters = [], array $httpHeaders = []) : string {
return $this->callEndpoint($manager, RequestMethod::GET, $endpoint, $parameters, $httpHeaders);
}
/**
* Sends a POST request to specific endpoint.
Expand All @@ -173,11 +181,15 @@ public function getRequest(WebServicesManager $manager, string $endpoint, array
* @param array $parameters An optional array of request parameters that can be
* passed to the endpoint.
*
* @param array $httpHeaders An optional associative array that can be used
* to mimic HTTP request headers. The keys of the array are names of headers
* and the value of each key represents the value of the header.
*
* @return string The method will return the output that was produced by
* the endpoint as string.
*/
public function postRequest(WebServicesManager $manager, string $endpoint, array $parameters = []) : string {
return $this->callEndpoint($manager, RequestMethod::POST, $endpoint, $parameters);
public function postRequest(WebServicesManager $manager, string $endpoint, array $parameters = [], array $httpHeaders = []) : string {
return $this->callEndpoint($manager, RequestMethod::POST, $endpoint, $parameters, $httpHeaders);
}
/**
* Sends a PUT request to specific endpoint.
Expand All @@ -189,11 +201,15 @@ public function postRequest(WebServicesManager $manager, string $endpoint, array
* @param array $parameters An optional array of request parameters that can be
* passed to the endpoint.
*
* @param array $httpHeaders An optional associative array that can be used
* to mimic HTTP request headers. The keys of the array are names of headers
* and the value of each key represents the value of the header.
*
* @return string The method will return the output that was produced by
* the endpoint as string.
*/
public function putRequest(WebServicesManager $manager, string $endpoint, array $parameters = []) : string {
return $this->callEndpoint($manager, RequestMethod::PUT, $endpoint, $parameters);
public function putRequest(WebServicesManager $manager, string $endpoint, array $parameters = [], array $httpHeaders = []) : string {
return $this->callEndpoint($manager, RequestMethod::PUT, $endpoint, $parameters, $httpHeaders);
}
private function extractPathAndName($absPath): array {
$DS = DIRECTORY_SEPARATOR;
Expand All @@ -219,11 +235,23 @@ private function extractPathAndName($absPath): array {
'path' => ''
];
}
private function unset(array &$arr, array $params, WebServicesManager $m) {
private function unset(array &$arr, array $params, WebServicesManager $m, array $httpHeaders) {
foreach ($httpHeaders as $header => $value) {
$trHeader = trim($header.'');
$trVal = trim($value.'');
if (strlen($trHeader) != 0) {
$_SERVER['HTTP_'.strtoupper($trHeader)] = $trVal;
}
}
$m->process();

foreach ($params as $key => $val) {
unset($arr[$key]);
}

foreach ($httpHeaders as $header => $value) {
$trHeader = trim($header.'');
unset($_SERVER['HTTP_'.strtoupper($trHeader)]);
}
}
}

0 comments on commit 38f4aa9

Please sign in to comment.