Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] Add option to render Surrogate fragment with absolute URIs#46514

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.2fromKern046:esi-fragment-absolute-urls
Jul 29, 2022

Conversation

@Kern046
Copy link

@Kern046Kern046 commentedMay 30, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
Tickets
LicenseMIT
Doc PR

Context

Using ESI blocks with Cloudflare Workers we faced an issue with the/_fragment relative URIs, as Cloudflare didn't succeed to handle it. We needed the absolute URL to make it work.

Proposed solution

In Symfony's codebase I noticed thatSymfony\Component\HttpKernel\Fragment\FragmentUriGenerator::generate already supports a$absolute parameter to fit the needs offragment_uri Twig function (I even wonder if this wasn't a previously supported feature when I see#8879), but this parameter couldn't be set throughrender_esi.

This PR adds the support of a newabsolute_uri option in order to set this parameter and get an absolute URI for ESI and SSI fragments. It only applies when using aControllerReference as the URI oralt option. It defaults tofalse to avoid causing any BC break.

Naming

I am not that confident about the naming:

  • I usedabsolute_uri for the option to keep it more self-descriptive than justabsolute.
  • I used$absolute to keep it more consistent with the existing parameters and usage inHttpKernelRuntime::generateFragmentUri.

I have doubts about the pertinence of such a diff between the option and the variable name. Let me know what you think about it !

Kocal and Geekimo reacted with eyes emoji
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

Kern046 reacted with hooray emoji

@carsonbot
Copy link

Hey!

I think@codedmonkey has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

codedmonkey reacted with thumbs down emoji

@nicolas-grekas
Copy link
Member

Would it make sense not add any option and always make the URL absolute instead?

@Kern046
Copy link
Author

Would it make sense not add any option and always make the URL absolute instead?

Wouldn't be a problem to do so, but as#8879 was meant to allow relative URLs, I am not sure that it wouldn't override some users needs. Ready to update the PR in that direction if needed :)

@nicolas-grekas
Copy link
Member

#8879 was meant to allow relative URLs

thanks for the pointer, let's not change that

we faced an issue with the /_fragment relative URIs, as Cloudflare didn't succeed to handle it

Can't this issue be solved without adding this option? Is that problem common to all Cloudflare users or is there something specific to your use case? Did you talk to their support to understand what the issue is? Maybe it's an issue on their side?

@Kern046
Copy link
Author

Kern046 commentedJun 1, 2022
edited
Loading

Can't this issue be solved without adding this option?

Yeah absolutely. I can retrieve the right hostname from the Request URL and then make the Fragment URL absolute within the Worker's code. This issue isn't blocking, we just thought that it could be interesting that therender_esi method allows us to choose. This way we wouldn't have to handle relative URLs case in our worker's code.

EDIT: Furthermore I have ofc no trouble with closing this PR if you deem it unnecessary :). I understand that adding more flexibility to a method can make its responsibility more confusing and decrease the maintainability.

Is that problem common to all Cloudflare users or is there something specific to your use case ?

I think that all Cloudflare users wanting to use ESI with Symfony will get through this, because ESI with Cloudflare needs to use a Cloudflare Worker (which will intercept and parse the server response for<esi:include> tags and then fetch the blocks to replace the tag with their content before sending the response to the client).

My best guess is that Cloudflare Worker's environment is isolated and lacks some context to "guess" the current hostname to fetch a relative URL.

Did you talk to their support to understand what the issue is? Maybe it's an issue on their side?

I just sent a message on their official Discord to get their PoV on the matter. If I'm correct about Cloudflare Worker's isolation I would say that it's not an issue but it's by design.

@stof
Copy link
Member

stof commentedJun 1, 2022

My best guess is that Cloudflare Worker's environment is isolated and lacks some context to "guess" the current hostname to fetch a relative URL.

Well, the worker environment has the information about the URL (as it has access to the whole Request and Response objects). But the example worker given in their blog post does not try to resolve the ESI URL as a relative URL based on that context.

Kern046 reacted with thumbs up emoji

@nicolas-grekasnicolas-grekasforce-pushed theesi-fragment-absolute-urls branch from57f4a65 to0a78a2aCompareJuly 28, 2022 10:10
Allow usage of `absolute_uri` option when using `render_esi` or `render_ssi` in order to get absolute URIs.
@nicolas-grekasnicolas-grekasforce-pushed theesi-fragment-absolute-urls branch from0a78a2a tof9f3ed0CompareJuly 28, 2022 10:13
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

That's a simple enough change, let's do it.

Kern046 reacted with heart emoji
@fabpot
Copy link
Member

Thank you@Kern046.

Kern046 and tristanbes reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrchalasr approved these changes

+1 more reviewer

@KocalKocalKocal left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

7 participants

@Kern046@carsonbot@nicolas-grekas@stof@fabpot@Kocal@chalasr

[8]ページ先頭

©2009-2025 Movatter.jp