Skip to content

[Asset] Allows to download asset manifest over HTTP #35762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2020

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Feb 17, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #35761 Fix #33001
License MIT
Doc PR symfony/symfony-docs#13255
framework:
    assets:
        json_manifest_path: 'https://cdn.example.com/manifest.json'

@GromNaN GromNaN force-pushed the remote-manifest branch 2 times, most recently from dfdc390 to 17cf357 Compare February 17, 2020 23:43
@nicolas-grekas nicolas-grekas added this to the next milestone Feb 18, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Please mind the CI.

@GromNaN GromNaN force-pushed the remote-manifest branch 4 times, most recently from 8e3c79b to b027a5c Compare February 18, 2020 15:35
@GromNaN

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM, here are some nitpicking.

@GromNaN GromNaN force-pushed the remote-manifest branch 2 times, most recently from bfd0141 to 10dd62a Compare February 19, 2020 22:44
nicolas-grekas added a commit that referenced this pull request Feb 20, 2020
…omponent tests (GromNaN)

This PR was merged into the 3.4 branch.

Discussion
----------

Use strict assertSame instead of assertEquals in Asset component tests

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #35762 (comment)
| License       | MIT
| Doc PR        | N/A

Using `assertSame` instead of `assertEquals` is recommended when possible (see sebastianbergmann/phpunit-documentation-english#3). It is stricter and must be more efficient ([`===`](https://github.com/sebastianbergmann/phpunit/blob/8.5.2/src/Framework/Constraint/IsIdentical.php#L63) vs a [comparator class](https://github.com/sebastianbergmann/phpunit/blob/8.5.2/src/Framework/Constraint/IsEqual.php#L79)).

~~Also, removing useless string cast.~~

Commits
-------

e8f3e84 Use strict assertion in asset tests
@GromNaN GromNaN force-pushed the remote-manifest branch 2 times, most recently from c929d43 to d517ee3 Compare February 21, 2020 17:02
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Feb 21, 2020 via email

nicolas-grekas added a commit that referenced this pull request Feb 25, 2020
…es (GromNaN)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[HttpClient][DX] Add URL context to JsonException messages

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #35762 (comment)
| License       | MIT
| Doc PR        | N/A

In order to help when debugging incorrect JSON responses, this PR adds the requested URL to the error message.

Before: `Syntax Error`
After: `JSON error: Syntax error, from "https://example.com/file.json".`
See the 2nd commit for full diff in new unit tests

Commits
-------

0653917 [HttpClient][DX] Add URL context to JsonException messages
@GromNaN
Copy link
Member Author

GromNaN commented Feb 26, 2020

Absolutely, it needs to be cached. And the cache needs to be served in case of error. IMO this is the responsability of the HttpClient to handle this behavior.
It's a good job that the CachingHttpClient already handles stale-while-revalidate and stale-if-error.

I'm trying to create a demo app to show the feature, but I don't find the correct config for http_client.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

IMO this is the responsibility of the HttpClient to handle this behavior.

I'm not sure about that: there are many benefits in using CacheInterface that won't be achieved by a CachingHttpClient (sharing of the cache, lock while fetching, probabilistic expiration, etc).

But this could be handled in a separate PR that adds a generic CachedManifestVersionStrategy, so that both ways are possible in the end.

Which means I'm good here, whith one last comment.

@GromNaN GromNaN force-pushed the remote-manifest branch 2 times, most recently from b6b5d59 to 7e45e6e Compare February 26, 2020 12:01
Copy link
Member Author

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

I simplified the code to the simplest form. The CachedManifestVersionStrategy is a clever idea that would solve performance and high availability issues. I can work on it once this PR gets merged.

Commits has been squashed & rebased.

Handle URL in json_manifest_path
Download the manifest using the HttpClient
@nicolas-grekas
Copy link
Member

Anyone else @symfony/mergers?

@weaverryan
Copy link
Member

I like this. Practical question: how could/should someone add caching? Decorate the service? Something else? There just needs to be a reasonable way and it's ok if it's simply covered in the docs.

@nicolas-grekas
Copy link
Member

@weaverryan check #35762 (review)

@nicolas-grekas
Copy link
Member

Thank you @GromNaN.

@nicolas-grekas nicolas-grekas merged commit 0647508 into symfony:master Apr 5, 2020
@nicolas-grekas
Copy link
Member

@GromNaN would you like to give CachedManifestVersionStrategy a try?

@GromNaN GromNaN deleted the remote-manifest branch April 6, 2020 07:55
@GromNaN
Copy link
Member Author

GromNaN commented Apr 6, 2020

I'll open a PR today.

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 17, 2020
This PR was squashed before being merged into the master branch.

Discussion
----------

[Asset] Document remote JSON manifest

Documentation for symfony/symfony#35762

- New feature for Asset component
- Integration in FrameworkBundle configuration

Commits
-------

be4760c [Asset] Document remote JSON manifest
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants