Skip to content

Comments

Ability to modify response headers (mainly cache related headers)#2288

Merged
dunglas merged 10 commits intoapi-platform:masterfrom
silverbackdan:modify-cache-headers
Nov 1, 2018
Merged

Ability to modify response headers (mainly cache related headers)#2288
dunglas merged 10 commits intoapi-platform:masterfrom
silverbackdan:modify-cache-headers

Conversation

@silverbackdan
Copy link
Contributor

@silverbackdan silverbackdan commented Oct 29, 2018

The cache headers should be able to be modified and then not overwritten by the AddHeadersListener. Also added annotation configuration for cache header expiry times so each resource can have a different expiry time if required.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #2207
License MIT
Doc PR api-platform/docs#702

A user may wish to define response cache headers in a custom controller or per resource. E.g. a /entity/random endpoint should have a max-age of 0
Add annotation attributes for cache_headers which allows max_age and shared_max_age to be assigned per resource.
The property was added when I thought it may be good to have the option outside of 'attributes' - decided to put the option in attributes instead and failed to remove this property.
Copy link
Contributor

@antograssiot antograssiot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the core members approve the change, it will be necessary to also add a private $cacheHeaders property to ApiResource too.

@dunglas
Copy link
Member

dunglas commented Oct 29, 2018

👍 on my side when @antograssiot's comments will be fixed! Thanks to both of you!

- Order of constructor arguments + default null value
- Remove 'throws' annotation
- setting $resourceCacheHeaders with default fallback to empty array
- Improved conditional statements
@silverbackdan
Copy link
Contributor Author

silverbackdan commented Oct 30, 2018

Is it worth re-running behat-coverage? It seems the behat tests all worked fine on other checkers but failed on that one.
It'll re-run when I do the next comment

Updated attribute annotation to alphabetical order - moved the property into alphabetical order as well
@dunglas dunglas merged commit d3e3733 into api-platform:master Nov 1, 2018
@dunglas
Copy link
Member

dunglas commented Nov 1, 2018

Thanks @silverbackdan!

cr3a7ure added a commit to cr3a7ure/core that referenced this pull request Nov 5, 2018
* ApiPlatformExtension cleanup

* Remove a now useless composer hack

* remove unset attributes key in normalization context

* Add tests on doctrine collection purge

* Fix 2285 - force Yaml::dump to dump empty array as actual empty array

* improve graphiql CSS

* Prefix root resource route_prefix to sub-resources

Unit test also added

* Bump PHPStan analysis to level 6 (api-platform#2272)

* Bump PHPStan analysis to level 6

* Bump PHPStan analysis to level 6

* Bump PHPStan analysis to level 6

* Deprecate dead code in QueryJoinParser and remove internal usage

* Add a non regression test for api-platform#2285 api-platform#2286

* Ability to modify response headers (mainly cache related headers) (api-platform#2288)

* Allow user-defined cache headers

A user may wish to define response cache headers in a custom controller or per resource. E.g. a /entity/random endpoint should have a max-age of 0

* Override cache max-age and shared-max-age

Add annotation attributes for cache_headers which allows max_age and shared_max_age to be assigned per resource.

* Remove unused property

The property was added when I thought it may be good to have the option outside of 'attributes' - decided to put the option in attributes instead and failed to remove this property.

* Code style fixes

* Test code style fix

* Review changes applied

- Order of constructor arguments + default null value
- Remove 'throws' annotation
- setting $resourceCacheHeaders with default fallback to empty array
- Improved conditional statements

* Add cacheHeaders Attribute annotation

* Accidental typo

* Alphabetical order

Updated attribute annotation to alphabetical order - moved the property into alphabetical order as well

* Add data providers and data persisters matches to the debug panel (api-platform#2262)

* Add data providers and data persisters matches to the debug panel

* Add tests on traceable providers and persisters

* Use internal public properties

* Merge config file and add tests on Extension

* Avoid extra loop in data persister/providers

* remove duplicated code

* Fix after rebasing

* Allow an input and an output for a given resource class

* [Bugfix] Remove type Error
dunglas added a commit to dunglas/doc that referenced this pull request Jan 8, 2019
antograssiot added a commit to api-platform/docs that referenced this pull request Jan 9, 2019
@silverbackdan silverbackdan deleted the modify-cache-headers branch April 3, 2020 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants