Skip to content

Commit d0849a1

Browse files
author
Lee Hicks
committed
DF-1254 #resolve #comment Allow setting response headers from output of script or external call from within scripting
1 parent be25d4a commit d0849a1

9 files changed

Lines changed: 24 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased]
6+
### Added
7+
- DF-1254 Allow setting response headers in all cases
68
### Changed
79
- DF-1226 Remove deprecated v8js extension methods
10+
- Use new df-system repository
811

912
## [0.7.0] - 2017-11-03
1013
### Changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
}
2626
],
2727
"require": {
28-
"dreamfactory/df-core": "~0.13.0"
28+
"dreamfactory/df-core": "~0.13.0",
29+
"dreamfactory/df-system": "~0.1.0"
2930
},
3031
"autoload": {
3132
"psr-4": {
@@ -36,7 +37,7 @@
3637
"branch-alias": {
3738
"dev-develop": "0.7.x-dev"
3839
},
39-
"laravel": {
40+
"laravel": {
4041
"providers": [
4142
"DreamFactory\\Core\\Script\\ServiceProvider"
4243
]

src/Components/BaseEngineAdapter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,14 @@ protected static function externalRequest($method, $url, $payload = [], $curlOpt
367367
throw new RestException($status, $result, $status);
368368
}
369369

370-
return ResponseFactory::create($result, $contentType, $status);
370+
$resultHeaders = Curl::getLastResponseHeaders();
371+
if ('chunked' === array_get(array_change_key_case($resultHeaders, CASE_LOWER), 'transfer-encoding')) {
372+
// don't relay this header through to client as it isn't handled well in some cases
373+
unset($resultHeaders['Transfer-Encoding']); // normal header case
374+
unset($resultHeaders['transfer-encoding']); // Restlet has all lower for this header
375+
}
376+
377+
return ResponseFactory::create($result, $contentType, $status, $resultHeaders);
371378
}
372379

373380
/**

src/Handlers/Events/ScriptableEventHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use DreamFactory\Core\Events\PostProcessApiEvent;
1111
use DreamFactory\Core\Events\PreProcessApiEvent;
1212
use DreamFactory\Core\Events\ServiceEvent;
13-
use DreamFactory\Core\Resources\System\Cache;
1413
use DreamFactory\Core\Script\Components\ScriptHandler;
1514
use DreamFactory\Core\Script\Events\BaseEventScriptEvent;
1615
use DreamFactory\Core\Script\Events\EventScriptDeletedEvent;
1716
use DreamFactory\Core\Script\Events\EventScriptModifiedEvent;
1817
use DreamFactory\Core\Script\Jobs\ServiceEventScriptJob;
1918
use DreamFactory\Core\Script\Models\EventScript;
19+
use DreamFactory\Core\System\Resources\Cache;
2020
use DreamFactory\Core\Utility\ResponseFactory;
2121
use Illuminate\Contracts\Events\Dispatcher;
2222
use Illuminate\Foundation\Bus\DispatchesJobs;
@@ -83,8 +83,9 @@ public function handleApiEvent($event)
8383
$content = array_get($response, 'content');
8484
$contentType = array_get($response, 'content_type');
8585
$status = array_get($response, 'status_code', HttpStatusCodeInterface::HTTP_OK);
86+
$headers = (array)array_get($response, 'headers');
8687

87-
$event->response = ResponseFactory::create($content, $contentType, $status);
88+
$event->response = ResponseFactory::create($content, $contentType, $status, $headers);
8889
} else {
8990
// otherwise assume raw content
9091
$event->response = ResponseFactory::create($response);

src/Jobs/ServiceEventScriptJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Crypt;
66
use DreamFactory\Core\Events\ServiceEvent;
7-
use DreamFactory\Core\Resources\System\Cache;
87
use DreamFactory\Core\Script\Models\EventScript;
8+
use DreamFactory\Core\System\Resources\Cache;
99
use Log;
1010
use Session;
1111

src/Resources/System/EventScript.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use DreamFactory\Core\Exceptions\BadRequestException;
88
use DreamFactory\Core\Exceptions\BatchException;
99
use DreamFactory\Core\Exceptions\InternalServerErrorException;
10-
use DreamFactory\Core\Resources\System\BaseSystemResource;
10+
use DreamFactory\Core\System\Resources\BaseSystemResource;
1111
use DreamFactory\Core\Script\Models\EventScript as EventScriptModel;
1212
use DreamFactory\Core\Utility\ResourcesWrapper;
1313
use DreamFactory\Core\Utility\ResponseFactory;

src/Resources/System/ScriptType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DreamFactory\Core\Script\Resources\System;
44

5-
use DreamFactory\Core\Resources\System\ReadOnlySystemResource;
5+
use DreamFactory\Core\System\Resources\ReadOnlySystemResource;
66
use DreamFactory\Core\Script\Contracts\ScriptEngineTypeInterface;
77
use DreamFactory\Core\Exceptions\NotFoundException;
88
use DreamFactory\Core\Utility\ResourcesWrapper;

src/ServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use DreamFactory\Core\Enums\ServiceTypeGroups;
55
use DreamFactory\Core\Models\SystemTableModelMapper;
6-
use DreamFactory\Core\Resources\System\SystemResourceManager;
7-
use DreamFactory\Core\Resources\System\SystemResourceType;
6+
use DreamFactory\Core\System\Components\SystemResourceManager;
7+
use DreamFactory\Core\System\Components\SystemResourceType;
88
use DreamFactory\Core\Script\Components\ScriptEngineManager;
99
use DreamFactory\Core\Script\Facades\ScriptEngineManager as ScriptEngineManagerFacade;
1010
use DreamFactory\Core\Script\Handlers\Events\ScriptableEventHandler;

src/Services/Script.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ protected function processRequest()
220220
$content = array_get($result, 'content');
221221
$contentType = array_get($result, 'content_type');
222222
$status = array_get($result, 'status_code', HttpStatusCodeInterface::HTTP_OK);
223+
$headers = (array)array_get($result, 'headers');
223224

224-
return ResponseFactory::create($content, $contentType, $status);
225+
return ResponseFactory::create($content, $contentType, $status, $headers);
225226
}
226227

227228
// otherwise assume raw content

0 commit comments

Comments
 (0)